XmlTextWriter.WriteQualifiedName Method (String, String)

 

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

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

override WriteQualifiedName : 
        localName:string *
        ns:string -> unit

Parameters

localName
Type: System.String

The local name to write.

ns
Type: System.String

The namespace URI to associate with the name.

Exception Condition
ArgumentException

localName is either null or String.Empty.

localName is not a valid name according to the W3C Namespaces spec.

System_CAPS_noteNote

Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.

For example, the following Microsoft Visual C# code:

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:

<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 (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).

The following example writes out a portion of a XSD schema.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: