I am trying to get the PreviousSibling function work. But I keep
getting the error (Error accessing XML). Here is my code:
---------------------------------------------------------------------------
private i as integer
private strOutput as string = ""
sub page_load (obj as object, e as eventargs)
dim xmldoc as new XMLDocument()
try
xmldoc.Load(Server.MapPath("Geo.xml"))
ShowTree(xmldoc.DocumentElement)
catch ex as Exception
strOutput = "Error accessing XML file"
end try
output.Text = strOutput
end sub
sub ShowTree(node as XMLNode)
dim attrnode as XmlNode
dim map as XmlNamedNodeMap
If Not(node.HasChildNodes)
strOutput += "  <b>" & node.Value & "</b><br/>" &
vbcrlf
if (node.Value = "Alabama") then
dim node_temp as XMLNode
node_temp = node.PreviousSibling
strOutput += "  <b>" & node_temp.Value &
"</b><br/>" & vbcrlf
end if
Else
strOutput += "<b>" & node.Value & "</b>"
If node.HasChildNodes then
node = node.FirstChild
while not IsNothing(node)
ShowTree(node)
node = node.NextSibling
end while
end if
end if
end sub
---------------------------------------------------------------------------
The line that causes the error is the last one in this if statement:
if (node.Value = "Alabama") then
dim node_temp as XMLNode
node_temp = node.PreviousSibling
strOutput += "  <b>" & node_temp.Value &
"</b><br/>" & vbcrlf
end if
If I comment out the last line, everything works fine. My XML looks
like this:
<?xml version="1.0" encoding="UTF-8" ?>
- <Geo>
<abbrev>AL</abbrev>
<state>Alabama</state>
<capital>Montgomery</capital>
<timezone>C</timezone>
</Geo>
- <Geo>
<abbrev>AK</abbrev>
<state>Alaska</state>
<capital>Juneau</capital>
<timezone>A</timezone>
</Geo>
....
Any idea what I am doing wrong?
Thanks.