I am reading xml gps data using xmlreader.read(). I want to output all coordinate points that are not located within a line element. Below is contained within the file, and I want to exclude the coordinates listed.
<place>
<desc>home</desc>
<line>
<coordinate>123,123,123</coordinate>
<coordinate>1223,1223,22123</coordinate>
</line>
</place>
This is an example of a valid coordinate, that I want to output and process (all located within the same file):
<place>
<desc>home</desc>
<point>
<coordinate>123,123,123</coordinate>
</point>
</place>
The difference is that one is part of a line object, and the other is a point. I currently have this code, and its grabbing everything.
while (lxmlReader.Read())
{
if (lxmlReader.NodeType == XmlNodeType.Element)
{
if (lxmlReader.Name == "coordinate")
{
rtxtOutput.Text += "\r\nElement Name: " + lxmlReader.Name.ToString();
rtxtOutput.Text += " Value: " + lxmlReader.ReadInnerXml().ToString();
}
}
}
I am not sure how to do it (or if it is possible) using XmlReader – Have you considered loading the XML into an XmlDocument or XDocument object which will allow you to perform proper queries on it.
You could then do something like this:
You will find lots of samples of selecting nodes based on parents etc using XPath online.