I come from a vb6 background. New to .net and new to xml. I am trying to retrieve nodes from an xml file. I have found several methods used (xmltextreader/serialization, xmldocument, xpath) I'm using xpath simply because I got some results with it firstMy problem I am sure is namespace related but all examples I've found are much simpler than the xml I have. Here is part of the xml I need to access and a snippet of my code.
Trying to retrieve AxisFeedrate I have this:Code:<?xml version="1.0" encoding="utf-8"?> <MTConnectStreams xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:mtconnect.org:MTConnectStreams:1.2 http://mtconnect.org/schemas/MTConnectStreams_1.2.xsd" xmlns="urn:mtconnect.org:MTConnectStreams:1.2"> <Header creationTime="2012-11-29T12:30:19Z" instanceId="2" nextSequence="1918272" sender="Tarus MTConnect Instance" bufferSize="5000" firstSequence="1913272" lastSequence="1918271" version="1.2" /> <Streams> <DeviceStream name="Vertical Bridge" uuid="TPIVB1"> <ComponentStream component="Device" name="Vert" componentId="TPIVert"> <Events> <Availability dataItemId="avail" timestamp="2012-11-27T23:19:40Z" sequence="44">AVAILABLE</Availability> </Events> </ComponentStream> <ComponentStream component="Linear" name="X" componentId="X"> <Samples> <AxisFeedrate dataItemId="xs1" timestamp="2012-11-29T12:29:54Z" sequence="1717806" name="x_feed_cmd" subType="COMMANDED" units="MILLIMETER/SECOND">0</AxisFeedrate>
If I save the xml to a file and edit the root node to be simply <MTConnectStreams> everything works. Trying to follow namespace examples I've found online I made the following changes to my code. But I still get zero results back when restoring the original root node.Code:Dim xDoc As XPathDocument = New XPathDocument(sUrl) Dim xNav As XPathNavigator = xDoc.CreateNavigator Dim xIt As XPathNodeIterator = xNav.Select("//AxisFeedrate") Dim i As Integer For i = 1 To xIt.Count xIt.MoveNext() msgbox (xIt.Current.Value)
Can someone help me get past this hurdle?Code:Dim nsMgr = New XmlNamespaceManager(xNav.NameTable) nsMgr.AddNamespace("ns", "http://www.w3.org/2001/XMLSchema-instance") Dim xIt As XPathNodeIterator = xNav.Select("//ns:AxisFeedrate", nsMgr)


My problem I am sure is namespace related but all examples I've found are much simpler than the xml I have. Here is part of the xml I need to access and a snippet of my code.
Reply With Quote
