//
// (C) 2002 Kral Ferch
//
+// [FIXME]
+// Document state should be considered.
+//
using System;
using System.Collections;
string openElementPrefix;
string openElementNS;
bool hasRoot = false;
+ Hashtable writtenAttributes = new Hashtable ();
+ bool checkMultipleAttributes = false;
#endregion
// output namespace declaration if not exist.
string prefix = openElementPrefix;
string ns = openElementNS;
- if (ns != null/* && LookupPrefix (ns) != prefix*/)
+ openElementPrefix = null;
+ openElementNS = null;
+
+ // LAMESPEC: If prefix was already assigned another nsuri, then this element's nsuri goes away!
+
+ if (ns != null)
{
string formatXmlns = String.Empty;
if (ns != String.Empty)
else if (addDefaultNamespace)
formatXmlns = String.Format (" xmlns={0}{1}{0}", quoteChar, ns);
}
- else if ((prefix == String.Empty) && (namespaceManager.LookupNamespace (prefix) != String.Empty))
+ else if ((prefix == String.Empty) && (namespaceManager.LookupNamespace (prefix) != ns))
{
namespaceManager.AddNamespace (prefix, ns);
formatXmlns = String.Format (" xmlns={0}{0}", quoteChar);
}
- if(formatXmlns != String.Empty)
- w.Write(formatXmlns);
- openElementPrefix = null;
- openElementNS = null;
+ if(formatXmlns != String.Empty) {
+ string xmlns = formatXmlns.Trim ();
+ if (checkMultipleAttributes && !writtenAttributes.Contains (xmlns.Substring (0, xmlns.IndexOf ('='))))
+ w.Write(formatXmlns);
+ }
}
}
ws = WriteState.Content;
openStartElement = false;
attributeWrittenForElement = false;
+ checkMultipleAttributes = false;
+ writtenAttributes.Clear ();
}
public override void Flush ()
WriteStringInternal (data, false);
}
- [MonoTODO]
public override void WriteRaw (char[] buffer, int index, int count)
{
- throw new NotImplementedException ();
+ WriteStringInternal (new string (buffer, index, count), false);
}
public override void WriteStartAttribute (string prefix, string localName, string ns)
if ((prefix == "xml") && (localName == "space"))
openXmlSpace = true;
- if ((prefix == "xmlns") && (localName == "xmlns"))
- throw new ArgumentException ("Prefixes beginning with \"xml\" (regardless of whether the characters are uppercase, lowercase, or some combination thereof) are reserved for use by XML.");
+ if ((prefix == "xmlns") && (localName.ToLower ().StartsWith ("xml")))
+ throw new ArgumentException ("Prefixes beginning with \"xml\" (regardless of whether the characters are uppercase, lowercase, or some combination thereof) are reserved for use by XML: " + prefix + ":" + localName);
CheckState ();
if (openStartElement || attributeWrittenForElement)
formatSpace = " ";
+ // If already written, then break up.
+ if (checkMultipleAttributes &&
+ writtenAttributes.Contains (formatPrefix + localName))
+ return;
+
w.Write ("{0}{1}{2}={3}", formatSpace, formatPrefix, localName, quoteChar);
+ if (checkMultipleAttributes)
+ writtenAttributes.Add (formatPrefix + localName, formatPrefix + localName);
openAttribute = true;
attributeWrittenForElement = true;
ws = WriteState.Attribute;
+ if (prefix == String.Empty && localName == "xmlns") {
+ if (namespaceManager.LookupNamespace (prefix) == null)
+ namespaceManager.AddNamespace (prefix, ns);
+ } else if (prefix == "xmlns") {
+ if (namespaceManager.LookupNamespace (localName) == null)
+ namespaceManager.AddNamespace (localName, ns);
+ }
}
public override void WriteStartDocument ()
string encodingFormatting = "";
if (!nullEncoding)
- encodingFormatting = String.Format (" encoding={0}{1}{0}", quoteChar, w.Encoding.HeaderName);
+ encodingFormatting = String.Format (" encoding={0}{1}{0}", quoteChar, w.Encoding.WebName);
w.Write("<?xml version={0}1.0{0}{1}{2}?>", quoteChar, encodingFormatting, standaloneFormatting);
ws = WriteState.Prolog;
CheckState ();
CloseStartElement ();
+ writtenAttributes.Clear ();
+ checkMultipleAttributes = true;
if (prefix == null)
prefix = namespaceManager.LookupPrefix (ns);
if (prefix == null)
prefix = String.Empty;
- string formatXmlns = "";
string formatPrefix = "";
if(ns != null) {
formatPrefix = prefix + ":";
}
- w.Write ("{0}<{1}{2}{3}", indentFormatting, formatPrefix, localName, formatXmlns);
-
+ w.Write ("{0}<{1}{2}", indentFormatting, formatPrefix, localName);
openElements.Push (new XmlTextWriterOpenElement (formatPrefix + localName));
ws = WriteState.Element;
openElementPrefix = prefix;
namespaceManager.PushScope ();
-// if(ns != null)
-// namespaceManager.AddNamespace (prefix, ns);
indentLevel++;
}