Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

Deep XML support

2008-12-13

Deep XML support means that the Visual Basic compiler knows what XML is, in about the same way that it knows what a Visual Basic keyword or a string constant is. Since all objects in .NET have a ToString function, wherever you used to use a string with XML data, you can use XML directly. The advantage of this is that any XML syntax errors are detected at compile time. This will work fine:
MessageBox.Show(<myXmlElement>Hello!</myXmlElement>.ToString())  

To use variable values in your XML, use <%= and %> as delimiter. Example:

Dim X = “Hello!”
MessageBox.Show(<myXmlElement><%= X %></myXmlElement>.ToString())
 

Imagine the help you get from this when you are sending HTML code to the web browser in an ASP.NET application. Finally, if you need a variable that represents some XML data, the name of the type is XElement in System.Xml.Linq. XElement has a simple API to manipulate and query the XML data.

Dim MyData = <SomeData><Child>1</Child><Child>2</Child></SomeData>
MessageBox.Show(MyData.Nodes().Count().ToString())

Categories: Visual Basic 9

Tags: XML

Leave a Reply

Your email address will not be published. Required fields are marked *



En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips