Export (0) Print
Expand All

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.

  NameDescription
Public method Static member Parse(String) Creates a new XDocument from a string.
Public method Static member Parse(String, LoadOptions) Creates a new XDocument from a string, optionally preserving white space, setting the base URI, and retaining line information.
Top

This method parses a string and creates an XML tree.

The following example creates a string that contains XML. It then parses the string into an XDocument.

string str =
@"<?xml version=""1.0""?>
<!-- comment at the root level -->
<Root>
    <Child>Content</Child>
</Root>";
XDocument doc = XDocument.Parse(str);
Console.WriteLine(doc);

This example produces the following output:

<!-- comment at the root level -->
<Root>
  <Child>Content</Child>
</Root>

Community Additions

ADD
Show:
© 2014 Microsoft