How do i read entries from an XML file, separate it in variables and assign them to a table?

Posted on 2006-04-20
Last Modified: 2010-04-16
I want to get the  <name> and the <Point><coordinates> in a table ; lat, long and height.

<coordinates>-96.49996973904457,40.49996266664014,0</coordinates>  = lat,long,height

I want to use the dataset ReadXml to do this.


See below for XML file.

  <name>S3100 Master</name>
  <name>S3100 Slave</name>
Question by:mdalionheart
    1 Comment
    LVL 7

    Accepted Solution

    I would use .NET's XML tools as shown below.

    // Instantiate XmlDocument obj and load from file
    XmlDocument XmlDoc = new XmlDocument();
    XmlDoc.Load("path to file");

    // Get All PlaceMark nodes
    XmlNodeList Placemarks = XmlDoc.GetElementsByTagName("Placemark");

    // Loop through Placemark Nodes
    foreach(XmlNode N in Placemarks)
          String Name = N["name"].InnerText;
          String Coordinates = N["Point"]["coordinates"].InnerText;

          // Split by Comma
          Char[] SplitChar = {','};
          String[] SplitArray = Coordinates.Split(SplitChar);

          // Get Values as Decimal
          decimal Lat = Convert.ToDecimal(SplitArray[0]);
          decimal Long = Convert.ToDecimal(SplitArray[1]);
          decimal Height = Convert.ToDecimal(SplitArray[2]);

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now