Edit

How to: Create XML Literals (Visual Basic)

You can create an XML document, fragment, or element directly in code by using an XML literal. The examples in this topic demonstrate how to create an XML element that has three child elements, and how to create an XML document.

You can also use the LINQ to XML APIs to create LINQ to XML objects. For more information, see XElement.

To create an XML element

  • Create the XML inline by using the XML literal syntax, which is the same as the actual XML syntax.

    Dim contact1 As XElement = 
        
          Patrick Hines
          206-555-0144
          425-555-0145
        
    

    Run the code. The output of this code is:

    Patrick Hines

    206-555-0144

    425-555-0145

To create an XML document

  • Create the XML document inline. The following code creates an XML document that has literal syntax, an XML declaration, a processing instruction, a comment, and an element that contains another element.

    Dim libraryRequest As XDocument = 
        
        
        
        
            
        
    Console.WriteLine(libraryRequest)
    

    Run the code. The output of this code is:

See also