Create XDocument from XmlReader : XDocument « XML LINQ « VB.Net






Create XDocument from XmlReader

   

Imports System
Imports System.Reflection
Imports System.Xml

Module Module1

    Sub Main()

        Dim reader As XmlReader = XmlReader.Create("People.xml")
        Dim xml As XDocument = XDocument.Load(reader)
        Console.WriteLine(xml)

        Dim idperson As XElement = xml.Descendants("person").Last()
        idperson.Add(New XElement("id", _
                        New XAttribute("id", 1), _
                        New XAttribute("year", 2006), _
                        New XAttribute("salary", "1")))

        Dim sw As New IO.StringWriter()
        Dim w As XmlWriter = XmlWriter.Create(sw)
        xml.Save(w)
        w.Close()
        Console.WriteLine(sw.ToString())

    End Sub
End Module

   
    
    
  








Related examples in the same category

1.Add element to XDocument
2.Create new Xml document with XDocument and XElement
3.Create an in-memory XML document with XDocument
4.Get Xml encoding from XDocument
5.Load the Employees.xml and store the contents into an XDocument object
6.Get version from XDocument
7.Reading Rss feed with XDocument
8.Display the XML files declaration information with an XDocument object
9.Display the name of the root element in the loaded XML tree
10.Is Xml standalone
11.LocalName returns the name of the element as a string
12.Name property returns the XName class
13.XDocument Class represents an XML document.
14.Create XDocument class with the specified content.
15.Create XDocument class.
16.Create XDocument with hard code string
17.Create XDocument class with the specified XDeclaration and content.
18.XDocument.Declaration Property gets or sets the XML declaration for this document.
19.XDocument.DocumentType Property gets the Document Type Definition (DTD) for this document.
20.XDocument.Load (String) creates a new XDocument from a file.
21.XDocument.Load(String, LoadOptions) creates a new XDocument from a file, optionally preserving white space
22.XDocument.Load (TextReader) creates a new XDocument from a TextReader.
23.XDocument.Load (TextReader, LoadOptions)
24.XDocument.NodeType Property gets the node type for this node.
25.XDocument.Parse creates a new XDocument from a string.
26.XDocument.Parse Method creates a new XDocument from a string, optionally preserving white space
27.XDocument.Root Property gets the root element of the XML Tree for this document.
28.XDocument.Save (String) serialize this XDocument to a file, overwriting an existing file, if it exists.
29.XDocument.Save serialize this XDocument to a file, optionally disabling formatting.
30.XDocument.Save (TextWriter) serialize this XDocument to a TextWriter.
31.XDocument.Save (TextWriter, SaveOptions) serialize this XDocument to a TextWriter, optionally disabling formatting.
32.XObject.Document Property gets the XDocument for this XObject.
33.Extensions.XPathEvaluate