Redigera

Dela via


XmlWriter.WriteQualifiedName(String, String) Method

Definition

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:
 abstract void WriteQualifiedName(System::String ^ localName, System::String ^ ns);
public virtual void WriteQualifiedName (string localName, string ns);
public virtual void WriteQualifiedName (string localName, string? ns);
public abstract void WriteQualifiedName (string localName, string ns);
abstract member WriteQualifiedName : string * string -> unit
override this.WriteQualifiedName : string * string -> unit
abstract member WriteQualifiedName : string * string -> unit
Public Overridable Sub WriteQualifiedName (localName As String, ns As String)
Public MustOverride Sub WriteQualifiedName (localName As String, ns As String)

Parameters

localName
String

The local name to write.

ns
String

The namespace URI for the name.

Exceptions

localName is either null or String.Empty.

localName is not a valid name.

An XmlWriter method was called before a previous asynchronous operation finished. In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

Examples

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

Remarks

If ns maps to the current default namespace, no prefix is generated.

When writing attribute values, this method generates a prefix if ns is not found. When writing element content, it throws an exception if ns is not found.

Note

If a class derived from the XmlWriter does not override this method localName is not checked to be a valid W3C XML name. In such case, before calling this method, the validity of the string can be checked by IsName method.

For the asynchronous version of this method, see WriteQualifiedNameAsync.

Applies to