XmlNode.BaseURI XmlNode.BaseURI XmlNode.BaseURI XmlNode.BaseURI Property

定義

取得目前節點的基底 (Base) URI。Gets the base URI of the current node.

public:
 virtual property System::String ^ BaseURI { System::String ^ get(); };
public virtual string BaseURI { get; }
member this.BaseURI : string
Public Overridable ReadOnly Property BaseURI As String

屬性值

節點載入的位置;如果節點沒有基底 URI,則為 String.Empty。The location from which the node was loaded or String.Empty if the node has no base URI.

備註

網路 XML 檔是由使用各種 W3C 標準包含機制所匯總的資料區塊所組成,因此包含來自不同位置的節點。A networked XML document is comprised of chunks of data aggregated using various W3C standard inclusion mechanisms and therefore contains nodes that come from different places. @No__t-0 會告訴您這些節點來自何處。The BaseURI tells you where these nodes came from.

這個屬性的值會根據節點類型而有所不同。The value of this property varies depending on the node type. 例如,檔節點會傳回 @no__t 0 物件的位置。For example, Document nodes return the location of the XmlDocument object. 屬於外部 EntityReference 節點之子節點的節點會傳回實體本身的位置。Nodes which are child nodes of external EntityReference nodes return the location of the entity itself. 例如,請考慮下列 XML 檔:For example, consider the following XML document:

<!DOCTYPE item [  
<!ENTITY xyz SYSTEM "a/b.xml">  
]>  
<item num='123'>&xyz;</item>  

其中,外部實體 a/b.xml 包含 XML 文字: <test>123</test>where the external entity a/b.xml contains the XML text: <test>123</test>.

如果檔是從 http://server/mydata.xml 載入,BaseURI 會傳回下列內容:If the document is loaded from http://server/mydata.xml, BaseURI returns the following:

NodeTypeNodeType 名稱Name BaseURIBaseURI
屬性Attribute numnum http://server/mydata.xml
文件Document #document#document http://server/mydata.xml
DocumentTypeDocumentType 項目item http://server/mydata.xml
實體Entity xyzxyz http://server/mydata.xml
元素Element 項目item http://server/mydata.xml
EntityReferenceEntityReference xyzxyz http://server/mydata.xml
元素Element 測試test http://server/a/b.xml
TextText #text#text http://server/a/b.xml

BaseURI 會尋找實體參考界限,因此,如果展開實體,則不會保留這項資訊,而且此屬性會在所有情況下傳回 XmlDocument 物件的位置。BaseURI looks for entity reference boundaries, so if entities are expanded this information is not preserved and this property returns the location of the XmlDocument object in all cases.

第二個範例是,假設有下列 XML 檔:As a second example, given the following XML document:

<!DOCTYPE Mydata SYSTEM "http://localhost/doctype.dtd">  
<baa>&xyz;</baa>  

DTD 檔案包含下列各項:where the DTD file contains the following:

<!ENTITY xyz <E1>My Data</E1>  
<!ELEMENT baa #PCDATA>  
<!ATTLIST baa attr1 "woof">  

如果從 http://localhost/mydata.xml 載入 XML 檔,BaseURI 會針對每個節點傳回下列各項:If the XML document is loaded from http://localhost/mydata.xml, BaseURI returns the following for each of the nodes:

NodeTypeNodeType 名稱Name BaseURIBaseURI
文件Document #document#document http://localhost/mydata.xml
DocumentTypeDocumentType MydataMydata http://localhost/mydata.xml

@No__t-0 或 @no__t 1 屬性可以用來識別 DTD 檔案的載入位置。The XmlDocumentType.SystemId or XmlDocumentType.PublicId properties can be used to identify where the DTD file was loaded from.
元素Element baabaa http://localhost/mydata.xml
實體Entity xyzxyz http://localhost/doctype.dtd
EntityReferenceEntityReference xyzxyz http://localhost/mydata.xml
屬性Attribute woofwoof http://localhost/mydata.xml

注意

預設屬性的基底 URI 與它們所屬專案的基底 URI 相同。The base URI of a default attribute is the same as the base URI of the element to which they belong.

這個屬性是文件物件模型的 Microsoft 擴充功能。This property is a Microsoft extension to the Document Object Model (DOM).

適用於