XML Problem

RobinTibbs

Member
Joined
Nov 8, 2006
Messages
18
Programming Experience
Beginner
Probably missing something silly again ;) but i get the following error when trrying to read an xml file

'element wowPath cannot be found'

here is the code. bear i mind i know the structure of the xml file and it stays the same

VB.NET:
<Preferences>
     <wowPath>path</wowPath>
     <version>version</wowPath>
</Preferences>
VB.NET:
 Dim xmlR As XmlTextReader

        xmlR = New XmlTextReader("prefs.xml")
        xmlR.WhitespaceHandling = WhitespaceHandling.None
        xmlR.Read()

        Dim wowPath = xmlR.ReadElementString("wowPath")
        Dim bwVersion = xmlR.ReadElementString("bwVersion")

        TextBox1.AppendText("wowPath: " + wowPath + ControlChars.CrLf)
        TextBox1.AppendText("bwVersion: " + bwVersion + ControlChars.CrLf)

        xmlR.Close()
 
There is an error in the xml fragment (version/wowPath). You have to call Read twice before getting to the wowPath node. Also code ask for bwVersion node that don't exist.

XmlDocument and Xpath is much easier, example:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] xdoc [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Xml.XmlDocument[/SIZE]
[SIZE=2]xdoc.Load([/SIZE][SIZE=2][COLOR=#800000]"prefs.xml"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] prefs [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Xml.XmlNode = xdoc.SelectSingleNode([/SIZE][SIZE=2][COLOR=#800000]"/Preferences"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]TextBox1.AppendText([/SIZE][SIZE=2][COLOR=#800000]"wowPath: "[/COLOR][/SIZE][SIZE=2] + prefs([/SIZE][SIZE=2][COLOR=#800000]"wowPath"[/COLOR][/SIZE][SIZE=2]).InnerText + vbNewLine)[/SIZE]
[SIZE=2]TextBox1.AppendText([/SIZE][SIZE=2][COLOR=#800000]"version: "[/COLOR][/SIZE][SIZE=2] + prefs([/SIZE][SIZE=2][COLOR=#800000]"version"[/COLOR][/SIZE][SIZE=2]).InnerText + vbNewLine)[/SIZE]

Thread was moved to Xml forum.
 
Using the code above I get the following error:

VB.NET:
The 'wowPath' start tag on line 2 does not match the end tag of 'Preferences'. Line 4, position 3.
 
JohnH said:
There is an error in the xml fragment (version/wowPath).
Correct your xml document.
Internet Explorer parser said:
End tag 'wowPath' does not match the start tag 'version'.
 
Back
Top