Read XML element value

  • Thread starter Thread starter David Dvali
  • Start date Start date
D

David Dvali

Hello.

I have such XML file:
<root>
<elem1>
<optional>
Some data
<optional>
</elem1>
</root>
How can I get value of the "optional" node?

Thank you.
 
I can do it in NET, but I can to do it in CF.:(
in CF there is not SelectSingleNode method in XmlDocument class.
What can I use instead of this method in CF?
 
Check out if this works, it's code I use to select the max id using xpath in
..NET (not CF, but it might work)

Function GetMaxIdFromXml()
Dim NodeValue As String
Dim xpathDoc As XPathDocument
Dim xmlNav As XPathNavigator
Dim xmlNI As XPathNodeIterator
Dim MaxId As Integer = 0
Dim XmlPath As String
XmlPath = "file.xml"
xpathDoc = New XPathDocument(XmlPath)
xmlNav = xpathDoc.CreateNavigator()
xmlNI = xmlNav.Select("/articles/article/id")
While (xmlNI.MoveNext())
If MaxId < cInt(xmlNI.Current.Value) Then
MaxId = cInt(xmlNI.Current.Value)
End If
End While
Return MaxId + 1
End Function
 
Back
Top