XmlNode.BaseURI 属性
定义
获取当前节点的基 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. BaseURI会告诉你这些节点的来源。The BaseURI tells you where these nodes came from.
此属性的值根据节点类型的不同而异。The value of this property varies depending on the node type. 例如,文档节点返回对象的位置 XmlDocument 。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 |
|---|---|---|
| AttributeAttribute | numnum | http://server/mydata.xml |
| 文档Document | #document#document | http://server/mydata.xml |
| DocumentTypeDocumentType | itemitem | http://server/mydata.xml |
| 实体Entity | xyzxyz | http://server/mydata.xml |
| 元素Element | itemitem | http://server/mydata.xml |
| EntityReferenceEntityReference | xyzxyz | http://server/mydata.xml |
| 元素Element | 测试test | http://server/a/b.xml |
| 文本Text | #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">
如果从加载 XML 文档 http://localhost/mydata.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.xmlXmlDocumentType.SystemId或 XmlDocumentType.PublicId 属性可用于标识从中加载 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 |
| AttributeAttribute | 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.
此属性是文档对象模型 (DOM) 的 Microsoft 扩展。This property is a Microsoft extension to the Document Object Model (DOM).