XmlWriter.WriteQualifiedName(String, String) XmlWriter.WriteQualifiedName(String, String) XmlWriter.WriteQualifiedName(String, String) XmlWriter.WriteQualifiedName(String, String) Method

定義

在衍生類別中覆寫時,寫出命名空間限定名稱。When overridden in a derived class, writes out the namespace-qualified name. 這個方法會查詢在指定之命名空間範圍中的前置詞。This method looks up the prefix that is in scope for the given namespace.

public:
 virtual void WriteQualifiedName(System::String ^ localName, System::String ^ ns);
public virtual void WriteQualifiedName (string localName, string ns);
abstract member WriteQualifiedName : string * string -> unit
override this.WriteQualifiedName : string * string -> unit
Public Overridable Sub WriteQualifiedName (localName As String, ns As String)

參數

localName
String String String String

要寫入的區域名稱。The local name to write.

ns
String String String String

這個名稱的命名空間 URI。The namespace URI for the name.

例外狀況

localNamenullString.EmptylocalName is either null or String.Empty.

localName 不是有效的名稱。localName is not a valid name.

在先前的非同步作業完成前呼叫了 XmlWriter 方法。An XmlWriter method was called before a previous asynchronous operation finished. 在此情況下,會擲回 InvalidOperationException 與「非同步作業已經在進行中」的訊息。In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

範例

此範例會寫入下列項目:The example writes the following element:

<root xmlns:x="urn:abc">  
  <item href="#x:test"/>  
</root>  
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;
using (XmlWriter writer = XmlWriter.Create(Console.Out, settings))
{
    writer.WriteStartElement("root");
    writer.WriteAttributeString("xmlns", "x", null, "urn:abc");
    writer.WriteStartElement("item");
    writer.WriteStartAttribute("href", null);
    writer.WriteString("#");
    writer.WriteQualifiedName("test", "urn:abc");
    writer.WriteEndAttribute();
    writer.WriteEndElement();
    writer.WriteEndElement();
}
Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.OmitXmlDeclaration = True
Using writer As XmlWriter = XmlWriter.Create(Console.Out, settings)
  writer.WriteStartElement("root")
  writer.WriteAttributeString("xmlns", "x", Nothing, "urn:abc")
  writer.WriteStartElement("item")
  writer.WriteStartAttribute("href", Nothing)
  writer.WriteString("#")
  writer.WriteQualifiedName("test", "urn:abc")
  writer.WriteEndAttribute()
  writer.WriteEndElement()
  writer.WriteEndElement()
End Using

備註

如果ns會產生對應至目前的預設命名空間,沒有前置詞。If ns maps to the current default namespace, no prefix is generated.

如果這個方法在撰寫屬性的值時,會產生前置詞ns找不到。When writing attribute values, this method generates a prefix if ns is not found. 當寫入項目內容,它會擲回例外狀況如果ns找不到。When writing element content, it throws an exception if ns is not found.

注意

如果類別衍生自XmlWriter不會覆寫這個方法localName就不會檢查有效的 W3C XML 名稱。If a class derived from the XmlWriter does not override this method localName is not checked to be a valid W3C XML name. 在此情況下之前呼叫這個方法,, 該字串的有效性可以檢查IsName方法。In such case, before calling this method, the validity of the string can be checked by IsName method.

這個方法的非同步版本,請參閱WriteQualifiedNameAsyncFor the asynchronous version of this method, see WriteQualifiedNameAsync.

適用於