?
Solved

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

Posted on 2006-04-20
1
Medium Priority
?
274 Views
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.

Thanks

See below for XML file.


   <Placemark>
  <name>S3100 Master</name>
  <LookAt>
  <longitude>-96.49996973904457</longitude>
  <latitude>40.49996266664014</latitude>
  <range>171475.719801093</range>
  <tilt>-7.368672389214692e-014</tilt>
  <heading>0.0001293105357542513</heading>
  </LookAt>
  <styleUrl>#khStyle646</styleUrl>
  <Point>
  <coordinates>-96.49996973904457,40.49996266664014,0</coordinates>
  </Point>
  </Placemark>
  <Placemark>
  <name>S3100 Slave</name>
  <LookAt>
  <longitude>-96.49996973904457</longitude>
  <latitude>40.49996266664016</latitude>
  <range>171459.80860425</range>
  <tilt>-5.301313670526361e-013</tilt>
  <heading>0.000129310535758434</heading>
  </LookAt>
  <styleUrl>#khStyle646</styleUrl>
  <Point>
  <coordinates>-96.25985025620838,40.19459554836167,0</coordinates>
  </Point>
  </Placemark>
0
Comment
Question by:mdalionheart
1 Comment
 
LVL 7

Accepted Solution

by:
mmarksbury earned 2000 total points
ID: 16502652
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]);
}
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses

840 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