public class XPathDocument : IXPathNavigable
|
ctor #1 | Overloaded:.ctor(Stream stream) Initializes a new instance of the XPathDocument class. |
ctor #2 | Overloaded:.ctor(string uri) Initializes a new instance of the XPathDocument class. |
ctor #3 | Overloaded:.ctor(TextReader reader) Initializes a new instance of the XPathDocument class. |
ctor #4 | Overloaded:.ctor(XmlReader reader) Initializes a new instance of the XPathDocument class. |
ctor #5 | Overloaded:.ctor(string uri, XmlSpace space) Initializes a new instance of the XPathDocument class. |
ctor #6 | Overloaded:.ctor(XmlReader reader, XmlSpace space) Initializes a new instance of the XPathDocument class. |
CreateNavigator | Creates an XPathNavigator for navigating this document. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public XPathDocument( |
stream
Exception Type | Condition |
---|---|
XmlException | There is a fatal error in the XML. In this case, the XPathDocument remains empty. |
public XPathDocument( |
uri
Exception Type | Condition |
---|---|
XmlException | There is a fatal error in the XML. In this case, the XPathDocument remains empty. |
The following C# code creates an XPathDocument.
XPathDocument doc = new XPathDocument("data.xml");
public XPathDocument( |
reader
Exception Type | Condition |
---|---|
XmlException | There is a fatal error in the XML. In this case, the XPathDocument remains empty. |
public XPathDocument( |
reader
Exception Type | Condition |
---|---|
XmlException | There is a fatal error in the XML. In this case, the XPathDocument remains empty. |
If the XmlReader is positioned on a leaf node that is invalid for the root level of a document, for example a whitespace or attribute node, the reader continues to read until it is positioned on a node that can be used for the root. The document begins loading at this point.
The XPathDocument can be used to load an XML fragment. If the XML fragment includes multiple sibling nodes, XPathDocument creates a root node and encapsulates the fragment nodes. Any white space found at the root level of the document or fragment is ignored. To preserve white space, use the overload that accepts an XmlSpace as an argument.
XmlTextReader reader = new XmlTextReader("books.xml"); reader.MoveToContent(); reader.Read(); reader.Skip(); // Skip the first book. reader.Skip(); // Skip the second book. // Create the document. XPathDocument doc = new XPathDocument(reader);
uri
space
reader
space
Exception Type | Condition |
---|---|
XmlException | There is a fatal error in the XML. In this case, the XPathDocument remains empty. |
If the XmlReader is positioned on a leaf node that is invalid for the root level of a document, for example a whitespace or attribute node, the reader continues to read until it is positioned on a node that can be used for the root. The document begins loading at this point.
The XPathDocument can be used to load an XML fragment. If the XML fragment includes multiple sibling nodes, XPathDocument creates a root node and encapsulates the fragment nodes.// Load data returned from SQL Server into an XmlTextReader. string mySelectQuery = "SELECT Customers.CompanyName, Orders.OrderID FROM Customers " + "INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID " + "WHERE CompanyName LIKE 'E%' FOR XML AUTO, XMLDATA, " + "ELEMENTS, BINARY BASE64"; string myConnectString = "server=localhost;Integrated Security=True;database=northwind"; SqlConnection sqlConn = new SqlConnection( myConnectString ); sqlConn.Open(); SqlCommand sqlComm = new SqlCommand( mySelectQuery , sqlConn); sqlComm.CommandTimeout = 15; XmlTextReader reader = (XmlTextReader)sqlComm.ExecuteXmlReader( ); // Instantiate an XPathDocument using the XmlTextReader. XPathDocument doc = new XPathDocument(reader, XmlSpace.Preserve);
public XPathNavigator CreateNavigator(); |
~XPathDocument(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |