XPathDocument 建構函式

定義

初始化 XPathDocument 類別的新執行個體。

多載

XPathDocument(Stream)

初始化指定 XPathDocument 物件中 XML 資料之 Stream 類別的新執行個體。

XPathDocument(String)

初始化指定檔案中 XML 資料之 XPathDocument 類別的新執行個體。

XPathDocument(XmlReader)

初始化指定 XPathDocument 物件中所包含 XML 資料之 XmlReader 類別的新執行個體。

XPathDocument(TextReader)

初始化指定 XPathDocument 物件中所包含 XML 資料之 TextReader 類別的新執行個體。

XPathDocument(String, XmlSpace)

以指定的空白區處理,初始化指定檔案中 XML 資料之 XPathDocument 類別的新執行個體。

XPathDocument(XmlReader, XmlSpace)

以指定的空白區處理,初始化指定 XPathDocument 物件中所包含 XML 資料之 XmlReader 類別的新執行個體。

XPathDocument(Stream)

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

初始化指定 XPathDocument 物件中 XML 資料之 Stream 類別的新執行個體。

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)

參數

stream
Stream

Stream 物件,包含 XML 資料。

例外狀況

XML 資料中發生錯誤。 XPathDocument 仍為空。

做為參數傳遞的 Stream 物件為 null

適用於

XPathDocument(String)

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

初始化指定檔案中 XML 資料之 XPathDocument 類別的新執行個體。

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)

參數

uri
String

包含 XML 資料的檔案路徑。

例外狀況

XML 資料中發生錯誤。 XPathDocument 仍為空。

檔案路徑參數為 null

備註

若要保留空白字元,請使用 XPathDocument 接受 物件做為參數的 XmlSpace 建構函式。

適用於

XPathDocument(XmlReader)

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

初始化指定 XPathDocument 物件中所包含 XML 資料之 XmlReader 類別的新執行個體。

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)

參數

reader
XmlReader

XmlReader 物件,包含 XML 資料。

例外狀況

XML 資料中發生錯誤。 XPathDocument 仍為空。

做為參數傳遞的 XmlReader 物件為 null

備註

XmlReader物件可用來將整個 XML 檔或 XML 檔的一部分載入至 XPathDocument 。 若要將 XML 檔的 XPathDocument 一部分載入 至 ,請將 XmlReader 物件放在最上方 XML 節點上以載入資料的來源。 當您使用 XPathDocument 建構函式建立 XPathDocument 時,資料會透過其所有同層級從目前最上層節點載入。 之後,會 XmlReader 放置在頂端 XML 節點的外部範圍上。 或者,您可以使用 ReadSubtree 方法將 載入 XPathDocument XML 檔中的特定專案。

以下是當您使用建 XPathDocument 構函式時要考慮的重要注意事項。

  • XmlReader具有適當關聯 XmlResolver 物件設定的物件可用來解析 XML 資料中的實體或其他參考。

  • XmlReader如果物件位於檔根層級不正確分葉節點上,例如,空白字元或屬性節點 - XmlReader 物件會繼續讀取,直到該物件位於可用於根目錄的節點上為止。 此時 XPathDocument 會開始載入。

  • 若要保留空白字元,請使用 XPathDocument 接受 物件做為參數的 XmlSpace 建構函式。

適用於

XPathDocument(TextReader)

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

初始化指定 XPathDocument 物件中所包含 XML 資料之 TextReader 類別的新執行個體。

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)

參數

textReaderreader
TextReader

TextReader 物件,包含 XML 資料。

例外狀況

XML 資料中發生錯誤。 XPathDocument 仍為空。

做為參數傳遞的 TextReader 物件為 null

備註

物件 TextReader 用來載入 XML 資料之後,物件的游標 TextReader 會放在資料結尾。 TextReader必須重設 物件,才能再次讀取資料。

適用於

XPathDocument(String, XmlSpace)

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

以指定的空白區處理,初始化指定檔案中 XML 資料之 XPathDocument 類別的新執行個體。

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)

參數

uri
String

包含 XML 資料的檔案路徑。

space
XmlSpace

XmlSpace 物件。

例外狀況

XML 資料中發生錯誤。 XPathDocument 仍為空。

檔案路徑參數或 XmlSpace 物件參數為 null

備註

  • XmlSpace當做參數傳遞的物件會指定是否要保留空白字元。 Default 只保留顯著的空白字元; Preserve 會保留所有空白字元。 根據預設, XmlSpace 物件會設定為 Default

  • 建構函式的功能與建構函式的功能 XPathDocument 相同 XPathDocument ,但所述的空白字元處理選項除外。

另請參閱

適用於

XPathDocument(XmlReader, XmlSpace)

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

以指定的空白區處理,初始化指定 XPathDocument 物件中所包含 XML 資料之 XmlReader 類別的新執行個體。

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)

參數

reader
XmlReader

XmlReader 物件,包含 XML 資料。

space
XmlSpace

XmlSpace 物件。

例外狀況

XML 資料中發生錯誤。 XPathDocument 仍為空。

XmlReader 物件參數或 XmlSpace 物件參數為 null

備註

  • XmlSpace當做參數傳遞的物件會指定是否要保留空白字元。 Default 只保留顯著的空白字元; Preserve 會保留所有空白字元。 根據預設, XmlSpace 物件會設定為 Default

  • 建構函式的功能與建構函式的功能 XPathDocument 相同 XPathDocument ,但所述的空白字元處理選項除外。

另請參閱

適用於