The basic syntax
for this is
XElement(XName name, params object[] content)
A pseudo-code example of this would be the following:
XElement employee = new XElement(XName,
new XElement(XName,
new XElement(XName name),
new XElement(XName name),
new XElement(XName name),
new XElement(XName name)
)
Here??™s an example of the syntax using real data, passing more than one XElement for the content:
XElement employee = new XElement("Root",
new XElement("Employee",
new XElement("Name", "Scott"),
127
Part II: LINQ to XML
new XElement("Title", "All Things Techy"),
new XElement("HireDate", "02/05/2007"),
new XElement("Gender", "M")
)
As you have seen in previous examples in this chapter and the last chapter, this is the ideal way to
construct an XML tree.
Now take a look at how to do the same thing in Visual Basic .NET.
Creating Trees in Visual Basic
Creating XML trees in Visual Basic is accomplished through XML literals. XML literals enable you to
create and incorporate XML directly into our Visual Basic programs and code. Another way to say this is
that XML literals let you type XML directly into your Visual Basic code without the need for any special
formatting.
Pages:
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230