Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.
2009-07-31
This post is more of a reminder to my self to start to deep xml support more seriously. I have mentioned it before, but not really examined it yet. For some reason, being free from work, leaves me with less time to just code for fun, compared to when I am working. Perhaps it’s good that my vacation soon is over.
To start off this “reminder”, I want to show how to create and manipulate an element. This creates and initializes an System.Xml.Linq.XElement:
Dim X = <myNode>MyValue</myNode>
To access the child value, I can use the Value property of X. I can read it or change it.
MessageBox.Show(X.Value)
Children are added to (called X in my example) using the Add method. This code:
X.Add(<child name=”child1″>Hello, mate!</child>)
X.Add(<child name=”child2″>Hello again, mate!</child>)
Results to this xml:
<myNode>MyValue <child name="child1">Hello, mate!</child> <child name="child2">Hello again, mate!</child> </myNode>
(It is not good practice to mix child elements with text values, but this is just an example.)
I use the ToString method to see the xml source of the XElement. To access my new children, I could get a reference using the Element method. This give me the first child (I pass the element name as an argument):
Dim Child = X.Element(“child”)
And to step to the next element, I could use the NextNode property:
Child = Child.NextNode
I hope to be able to give a practical example of this soon, but for now, I am still impressed with the deep support (meaning that the compiler detects syntax error in the xml code).
Categories: Visual Basic 9
Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!
Leave a Reply