Thursday, May 29, 2008

XML Code with VB Express 2008

Function CreateDocument()

Return_

<?xml
version="1.0"
encoding="UTF-16"
standalone="yes"?>


<organizer>


<contact
category="home">


<name>John Smith</name>


<address>New York</address>


</contact>


<contact
category="home">


<name>Layong</name>


<address>Indonesia</address>


</contact>


<contact
category="work">


<name>Jack Brock</name>


<address>London</address>


</contact>


</organizer>

End
Function


The code above show us how to create XML code more easier and in one framework. Vb 9 can regconize the XML code and execute those code like vb do with their own code.

Those code will return the result in xml code with "organizer" as a root. What vb 9 can do with those xml code is truly amazing. We can play with xml code and generate the xml code again.


Here the example:

Sub testingXML()


Dim doc() = CreateDocument()


Console.WriteLine(doc(0))



Dim contacts = From cont In doc.Descendants("organizer") _


Where cont.Attribute("category").Value = "home" _


Select cont



Dim contacts2 = From cont2 In doc...<organizer> _


Select cont2



For
Each contact In contacts

Console.WriteLine(contact)


Next



For
Each contact2 In contacts2.<contact>

Console.WriteLine("{0,-40} {1,-20}", contact2.<name>.Value, contact2.<address>.Value)


Next



Console.ReadKey()



End
Sub



Try it yourself what vb 9 get with those code. It's amazing. J

0 comments:

Google

Microsoft News for ADO .NET:

Our Email Address:

blog.programming@gmail.com