G
Guest
All
I have an XML document as illustrated in the extract below. I am trying to
use the XmlNodeReader to extract information from the document. What I am
having trouble with is when I read the line of the document I am unable to
read the value of the element. Below is an extract of the source code that I
am using to read the other parts of the document that I want to extract. Any
assistance would be appreciated.
Thanks
ie. What I am trying to extract
<value code="Mr">Mr</value> - want to extract "value"
<value code="Mrs">Mrs</value> - want to extract "value"
.....etc
<value code="NSW">NSW</value> - want to extract "value"
<caption>State:</caption> - want to extract "caption"
--- XML Doc ---
<root>
<selection attr="1">
<value code="Mr">Mr</value>
<value code="Mrs">Mrs</value>
<value code="Ms">Ms</value>
<value code="Miss">Miss</value>
<caption>Title:</caption>
</selection>
<selection attr="2">
<value code="QLD">QLD</value>
<value code="VIC">VIC</value>
<value code="NSW">NSW</value>
<caption>State:</caption>
</selection>
</root>
--- End XML Doc ---
--- Code ---
Dim sr As New System.IO.StreamReader("c:\xml.xml")
Dim sw As New System.IO.StreamWriter("c:\output.txt")
Dim attr As String
Dim doc As New Xml.XmlDocument
doc.Load(sr)
Dim reader As New Xml.XmlNodeReader(doc)
While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType.Element
If reader.Name = "selection" Then
attr = reader.GetAttribute("attr")
End If
Case Xml.XmlNodeType.Text
sw.WriteLine(attr & ", " & reader.Value)
End Select
End While
sw.Close()
--- End Code ---
I have an XML document as illustrated in the extract below. I am trying to
use the XmlNodeReader to extract information from the document. What I am
having trouble with is when I read the line of the document I am unable to
read the value of the element. Below is an extract of the source code that I
am using to read the other parts of the document that I want to extract. Any
assistance would be appreciated.
Thanks
ie. What I am trying to extract
<value code="Mr">Mr</value> - want to extract "value"
<value code="Mrs">Mrs</value> - want to extract "value"
.....etc
<value code="NSW">NSW</value> - want to extract "value"
<caption>State:</caption> - want to extract "caption"
--- XML Doc ---
<root>
<selection attr="1">
<value code="Mr">Mr</value>
<value code="Mrs">Mrs</value>
<value code="Ms">Ms</value>
<value code="Miss">Miss</value>
<caption>Title:</caption>
</selection>
<selection attr="2">
<value code="QLD">QLD</value>
<value code="VIC">VIC</value>
<value code="NSW">NSW</value>
<caption>State:</caption>
</selection>
</root>
--- End XML Doc ---
--- Code ---
Dim sr As New System.IO.StreamReader("c:\xml.xml")
Dim sw As New System.IO.StreamWriter("c:\output.txt")
Dim attr As String
Dim doc As New Xml.XmlDocument
doc.Load(sr)
Dim reader As New Xml.XmlNodeReader(doc)
While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType.Element
If reader.Name = "selection" Then
attr = reader.GetAttribute("attr")
End If
Case Xml.XmlNodeType.Text
sw.WriteLine(attr & ", " & reader.Value)
End Select
End While
sw.Close()
--- End Code ---