Writes out the namespace-qualified name. This method looks up the prefix that is in scope for the given namespace.
Type Reason 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.
InvalidOperationException The XmlTextWriter.WriteState is WriteState.Closed. System.Xml.XmlException localName is not a valid XML name.
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).