Share via


XmlTextReader.LookupNamespace(String) 方法

定義

解析目前項目範圍中的命名空間前置詞。

public:
 override System::String ^ LookupNamespace(System::String ^ prefix);
public override string? LookupNamespace (string prefix);
public override string LookupNamespace (string prefix);
override this.LookupNamespace : string -> string
Public Overrides Function LookupNamespace (prefix As String) As String

參數

prefix
String

您要解析其命名空間 URI 的前置詞。 若要符合預設命名空間,請傳送空字串。 不必擷取這個字串。

傳回

前置詞對應的命名空間 URI,如果找不到符合的前置詞,則為 null

例外狀況

Namespaces 屬性是設定為 true,而且 prefix 值為 null

備註

注意

從 .NET Framework 2.0 開始,建議您使用 XmlReader.Create 方法來建立 XmlReader 實例,以利用新功能。

在下列 XML 中,如果讀取器位於 屬性上 href ,則會呼叫 reader.LookupNamespace("a") 來解析前置詞 a 。 傳回的字串為 urn:456

<root xmlns:a="urn:456">
 <item>
 <ref href="a:b"/>
 </item>
</root>

適用於

另請參閱