System.Xml.XmlTextWriter.WriteQualifiedName Method

Writes out the namespace-qualified name. This method looks up the prefix that is in scope for the given namespace.

Syntax

public override void WriteQualifiedName (string localName, string ns)

Parameters

ns
The namespace URI to associate with the name.
localName
The local name to write.
ns
The namespace URI to associate with the name.

Exceptions

TypeReason
ArgumentException

localName is null or string.Empty.

-or-

XmlTextWriter.Namespaces is false, and ns is neither null nor string.Empty .

-or-

localName is not a valid XML name.

InvalidOperationExceptionThe XmlTextWriter.WriteState is WriteState.Closed.
System.Xml.XmlException localName is not a valid XML name.

Remarks

Note:

In the dnprdnext release, the recommended practice is to create System.Xml.XmlWriter instances using the erload:System.Xml.XmlWriter.Create method and the System.Xml.XmlWriterSettings class. This allows you to take full advantage of all the new features introduced in this release. For more information, see Creating XML Writers.

For example, the following Microsoft Visual C# code:

Example

 writer.Formatting = Formatting.Indented;
 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();
  writer.Close();

Generates the following output:

Example

 <root xmlns:x="urn:abc">
  <item href="#x:test"/>
  </root>

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.

If this writer supports namespaces (XmlTextWriter.Namespaces is set to true), this method also checks that the name is valid according to the W3C Namespaces in XML recommendation (http://www.w3.org/TR/REC-xml-names).

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0