I have a very simple problem, but since I am new to XML, I face some problems. I have this XML document:
<?xml version="1.0" encoding="utf-8"?>
<Form_Layout>
<Location>
<LocX>100</LocX>
<LocY>100</LocY>
</Location>
<Size>
<Width>300</Width>
<Height>300</Height>
</Size>
</Form_Layout>
What I want to do is read the values from the LocX, LoxY, Width, and Height elements into my corresponding variables.
Here is what I have tried:
Dim XmlReader = New XmlNodeReader(xmlDoc)
While XmlReader.Read
Select Case XmlReader.Name.ToString()
Case "Location"
If XmlReader.??
Case "Size"
If XmlReader.??
End Select
End While
But, I cannot figure out how to access each child Node.
If you're able to use Linq to XML, you can use VB's XML Axis Properties:
Dim root As XElement = XDocument.Load(fileName).Root
Dim LocX = Integer.Parse(root.<Location>.<LocX>.Value)
Dim LocY = Integer.Parse(root.<Location>.<LocY>.Value)
And root.<Location>.<LocY>.Value = CStr(120)
works too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With