편집

다음을 통해 공유


XPathDocument Constructors

Definition

Initializes a new instance of the XPathDocument class.

Overloads

XPathDocument(Stream)

Initializes a new instance of the XPathDocument class from the XML data in the specified Stream object.

XPathDocument(String)

Initializes a new instance of the XPathDocument class from the XML data in the specified file.

XPathDocument(XmlReader)

Initializes a new instance of the XPathDocument class from the XML data that is contained in the specified XmlReader object.

XPathDocument(TextReader)

Initializes a new instance of the XPathDocument class from the XML data that is contained in the specified TextReader object.

XPathDocument(String, XmlSpace)

Initializes a new instance of the XPathDocument class from the XML data in the file specified with the white space handling specified.

XPathDocument(XmlReader, XmlSpace)

Initializes a new instance of the XPathDocument class from the XML data that is contained in the specified XmlReader object with the specified white space handling.

XPathDocument(Stream)

Source:
XPathDocument.cs
Source:
XPathDocument.cs
Source:
XPathDocument.cs

Initializes a new instance of the XPathDocument class from the XML data in the specified Stream object.

public:
 XPathDocument(System::IO::Stream ^ stream);
public XPathDocument (System.IO.Stream stream);
new System.Xml.XPath.XPathDocument : System.IO.Stream -> System.Xml.XPath.XPathDocument
Public Sub New (stream As Stream)

Parameters

stream
Stream

The Stream object that contains the XML data.

Exceptions

An error was encountered in the XML data. The XPathDocument remains empty.

The Stream object passed as a parameter is null.

Applies to

XPathDocument(String)

Source:
XPathDocument.cs
Source:
XPathDocument.cs
Source:
XPathDocument.cs

Initializes a new instance of the XPathDocument class from the XML data in the specified file.

public:
 XPathDocument(System::String ^ uri);
public XPathDocument (string uri);
new System.Xml.XPath.XPathDocument : string -> System.Xml.XPath.XPathDocument
Public Sub New (uri As String)

Parameters

uri
String

The path of the file that contains the XML data.

Exceptions

An error was encountered in the XML data. The XPathDocument remains empty.

The file path parameter is null.

Remarks

To preserve white space, use the XPathDocument constructor that accepts an XmlSpace object as a parameter.

Applies to

XPathDocument(XmlReader)

Source:
XPathDocument.cs
Source:
XPathDocument.cs
Source:
XPathDocument.cs

Initializes a new instance of the XPathDocument class from the XML data that is contained in the specified XmlReader object.

public:
 XPathDocument(System::Xml::XmlReader ^ reader);
public XPathDocument (System.Xml.XmlReader reader);
new System.Xml.XPath.XPathDocument : System.Xml.XmlReader -> System.Xml.XPath.XPathDocument
Public Sub New (reader As XmlReader)

Parameters

reader
XmlReader

The XmlReader object that contains the XML data.

Exceptions

An error was encountered in the XML data. The XPathDocument remains empty.

The XmlReader object passed as a parameter is null.

Remarks

An XmlReader object can be used to load a whole XML document or part of an XML document into an XPathDocument. To load part of an XML document into an XPathDocument, position the XmlReader object on the top XML node to load data from. When you create an XPathDocument by using the XPathDocument constructor, data is loaded from the current top node through all its siblings. Afterwards, the XmlReader is positioned on the outer scope of the top XML node. Alternatively, you can use the ReadSubtree method to load the XPathDocument into a particular element in the XML document.

The following are important notes to consider when you use the XPathDocument constructor.

  • An XmlReader object with the appropriate associated XmlResolver object settings can be used to resolve entities or other references in XML data.

  • If the XmlReader object is positioned on a leaf node that is not valid for the root level of a document - for example, a white space or attribute node - the XmlReader object continues to read until it is positioned on a node that can be used for the root. The XPathDocument begins loading at this point.

  • To preserve white space, use the XPathDocument constructor that accepts an XmlSpace object as a parameter.

Applies to

XPathDocument(TextReader)

Source:
XPathDocument.cs
Source:
XPathDocument.cs
Source:
XPathDocument.cs

Initializes a new instance of the XPathDocument class from the XML data that is contained in the specified TextReader object.

public:
 XPathDocument(System::IO::TextReader ^ textReader);
public:
 XPathDocument(System::IO::TextReader ^ reader);
public XPathDocument (System.IO.TextReader textReader);
public XPathDocument (System.IO.TextReader reader);
new System.Xml.XPath.XPathDocument : System.IO.TextReader -> System.Xml.XPath.XPathDocument
new System.Xml.XPath.XPathDocument : System.IO.TextReader -> System.Xml.XPath.XPathDocument
Public Sub New (textReader As TextReader)
Public Sub New (reader As TextReader)

Parameters

textReaderreader
TextReader

The TextReader object that contains the XML data.

Exceptions

An error was encountered in the XML data. The XPathDocument remains empty.

The TextReader object passed as a parameter is null.

Remarks

After the TextReader object has been used to load XML data, the cursor of the TextReader object is positioned at the end of the data. The TextReader object must be reset to read through the data again.

Applies to

XPathDocument(String, XmlSpace)

Source:
XPathDocument.cs
Source:
XPathDocument.cs
Source:
XPathDocument.cs

Initializes a new instance of the XPathDocument class from the XML data in the file specified with the white space handling specified.

public:
 XPathDocument(System::String ^ uri, System::Xml::XmlSpace space);
public XPathDocument (string uri, System.Xml.XmlSpace space);
new System.Xml.XPath.XPathDocument : string * System.Xml.XmlSpace -> System.Xml.XPath.XPathDocument
Public Sub New (uri As String, space As XmlSpace)

Parameters

uri
String

The path of the file that contains the XML data.

space
XmlSpace

An XmlSpace object.

Exceptions

An error was encountered in the XML data. The XPathDocument remains empty.

The file path parameter or XmlSpace object parameter is null.

Remarks

  • The XmlSpace object passed as a parameter specifies whether to preserve white space. Default preserves only significant white space; Preserve preserves all white space. By default, the XmlSpace object is set to Default.

  • The functionality of the XPathDocument constructor is identical to that of the XPathDocument constructor, except for the white space handling options described.

See also

Applies to

XPathDocument(XmlReader, XmlSpace)

Source:
XPathDocument.cs
Source:
XPathDocument.cs
Source:
XPathDocument.cs

Initializes a new instance of the XPathDocument class from the XML data that is contained in the specified XmlReader object with the specified white space handling.

public:
 XPathDocument(System::Xml::XmlReader ^ reader, System::Xml::XmlSpace space);
public XPathDocument (System.Xml.XmlReader reader, System.Xml.XmlSpace space);
new System.Xml.XPath.XPathDocument : System.Xml.XmlReader * System.Xml.XmlSpace -> System.Xml.XPath.XPathDocument
Public Sub New (reader As XmlReader, space As XmlSpace)

Parameters

reader
XmlReader

The XmlReader object that contains the XML data.

space
XmlSpace

An XmlSpace object.

Exceptions

An error was encountered in the XML data. The XPathDocument remains empty.

The XmlReader object parameter or XmlSpace object parameter is null.

Remarks

  • The XmlSpace object passed as a parameter specifies whether to preserve white space. Default preserves only significant white space; Preserve preserves all white space. By default, the XmlSpace object is set to Default.

  • The functionality of the XPathDocument constructor is identical to that of the XPathDocument constructor, except for the white space handling options described.

See also

Applies to