System.Xml.XmlTextWriter.WriteQualifiedName C# (CSharp) Method

WriteQualifiedName() public method

public WriteQualifiedName ( string localName, string ns ) : void
localName string
ns string
return void
        public override void WriteQualifiedName(string localName, string ns) {
            try {
                AutoComplete(Token.Content);
                if (this.namespaces) {
                    if (ns != null && ns.Length != 0 && ns != stack[top].defaultNs) {
                        string prefix = FindPrefix(ns);
                        if (prefix == null) {
                            if (this.currentState != State.Attribute) {
                                throw new ArgumentException(Res.GetString(Res.Xml_UndefNamespace, ns));
                            }
                            prefix = GeneratePrefix(); // need a prefix if
                            PushNamespace(prefix, ns, false);
                        }
                        if (prefix.Length != 0) {
                            InternalWriteName(prefix, true);
                            textWriter.Write(':');
                        }
                    }
                }
                else if (ns != null && ns.Length != 0) {
                    throw new ArgumentException(Res.GetString(Res.Xml_NoNamespaces));
                }
                InternalWriteName(localName, true);
            }
            catch {
                currentState = State.Error;
                throw;
            }
        }

Usage Example

Example #1
0
		[Test] // bug #75546
		public void WriteEmptyNSQNameInAttribute ()
		{
			XmlTextWriter xtw = new XmlTextWriter (TextWriter.Null);
			xtw.WriteStartElement ("foo", "urn:goo");
			xtw.WriteAttributeString ("xmlns:bar", "urn:bar");
			xtw.WriteStartAttribute ("foo", "");
			xtw.WriteQualifiedName ("n1", "urn:bar");
			xtw.WriteEndAttribute ();
			xtw.WriteStartAttribute ("foo", "");
			xtw.WriteQualifiedName ("n2", "");
			xtw.WriteEndAttribute ();
		}