.NET Framework Class Library
XDocument.Parse Method
Creates a new XDocument from a string, optionally preserving white space, setting the base URI, and retaining line information.
This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.
Overload List
| Name | Description | |
|---|---|---|
|
Parse(String) | Creates a new XDocument from a string. |
|
Parse(String, LoadOptions) | Creates a new XDocument from a string, optionally preserving white space, setting the base URI, and retaining line information. |
Remarks
This method parses a string and creates an XML tree.
Examples
The following example creates a string that contains XML. It then parses the string into an XDocument.
C#
string str = @"<?xml version=""1.0""?> <!-- comment at the root level --> <Root> <Child>Content</Child> </Root>"; XDocument doc = XDocument.Parse(str); Console.WriteLine(doc);
Visual Basic
Dim str As String = _ "<?xml version= '1.0'?>" & _ "<!-- comment at the root level -->" & _ "<Root>" & _ " <Child>Content</Child>" & _ "</Root>" Dim doc As XDocument = XDocument.Parse(str) Console.WriteLine(doc)
This example produces the following output:
xmlLang
<!-- comment at the root level --> <Root> <Child>Content</Child> </Root>
See Also