//
// Author:
// Jason Diamond (jason@injektilo.org)
+// Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
//
// (C) 2002 Jason Diamond http://injektilo.org/
+// (C) 2002 Atsushi Enomoto
//
using System;
using System.Collections;
using System.Xml.XPath;
+using System.IO;
using System.Text;
namespace System.Xml
return base.InnerText;
}
set {
- foreach(XmlNode n in ChildNodes)
- {
- this.RemoveChild(n);
+ // Why its behavior (of MS FCL) is different from InnerXml...?
+ if (FirstChild != null && FirstChild.NodeType == XmlNodeType.Text)
+ FirstChild.Value = value;
+ else {
+ if(FirstChild != null) {
+ foreach (XmlNode n in ChildNodes)
+ this.RemoveChild (n);
+ }
+ // creates new Text node
+ AppendChild(OwnerDocument.CreateTextNode(value));
}
- // creates new Text node
- AppendChild(OwnerDocument.CreateTextNode(value));
}
}
- [MonoTODO ("Setter is immature")]
public override string InnerXml {
get {
- // Not sure why this is an override. Passing through for now.
return base.InnerXml;
}
set {
foreach(XmlNode n in ChildNodes)
- {
this.RemoveChild(n);
- }
- // How to get xml:lang and xml:space? Create logic as ConstructNamespaceManager()?
+ // I hope there are any well-performance logic...
XmlNameTable nt = this.OwnerDocument.NameTable;
- XmlNamespaceManager nsmgr = this.ConstructNamespaceManager(); //new XmlNamespaceManager(nt);
- string lang = "";
- XmlSpace space = XmlSpace.Default;
-
- XmlParserContext ctx = new XmlParserContext(nt, nsmgr, lang, space);
- XmlTextReader xmlReader = new XmlTextReader(value, this.NodeType, ctx);
- this.ConstructDOM(xmlReader, this);
+ XmlNamespaceManager nsmgr = this.ConstructNamespaceManager ();
+ XmlParserContext ctx = new XmlParserContext (nt, nsmgr, XmlLang, this.XmlSpace);
+ XmlTextReader xmlReader = OwnerDocument.ReusableReader;
+ xmlReader.SetReaderContext (String.Empty, ctx);
+ xmlReader.SetReaderFragment (new StringReader (value), XmlNodeType.Element);
+
+ do {
+ XmlNode n = OwnerDocument.ReadNode (xmlReader);
+ if(n == null) break;
+ AppendChild (n);
+ } while (true);
}
}
- [MonoTODO ("This is only a temporary fix, remove ASAP!")]
public bool IsEmpty {
get { return isEmpty; }
- set { isEmpty = value; }
+ set {
+ if(value)
+ RemoveAll();
+ isEmpty = value;
+ }
}
public override string LocalName {
childNode.WriteTo(w);
}
- [MonoTODO("indenting feature is incomplete.")]
+ [MonoTODO]
public override void WriteTo (XmlWriter w)
{
w.WriteStartElement(Prefix, LocalName, NamespaceURI);
- // write namespace declarations(if not exist)
- if(Prefix != null && w.LookupPrefix(Prefix) != NamespaceURI)
- w.WriteAttributeString("xmlns", Prefix, "http://www.w3.org/2000/xmlns/", NamespaceURI);
-
foreach(XmlNode attributeNode in Attributes)
- {
attributeNode.WriteTo(w);
- // write namespace declarations(if not exist)
- if(attributeNode.Prefix != null && w.LookupPrefix(attributeNode.Prefix) != attributeNode.NamespaceURI)
- w.WriteAttributeString("xmlns", attributeNode.Prefix, "http://www.w3.org/2000/xmlns/", attributeNode.NamespaceURI);
- }
- // indent(when PreserveWhitespace = false)
- // Only XmlWriter has this XmlElement's xml:space information;-)
- if(!OwnerDocument.PreserveWhitespace && w.XmlSpace != XmlSpace.Preserve)
- {
- XmlNode n = this;
- StringBuilder sb = new StringBuilder();
- while(n != OwnerDocument)
- {
- sb.Append('\t');
- n = n.ParentNode;
- }
- w.WriteWhitespace(sb.ToString());
+ // write namespace declarations(if not exist)
+ foreach(XmlNode attributeNode in Attributes) {
+ if(attributeNode.Prefix != null && attributeNode.Prefix != String.Empty &&\r
+ w.LookupPrefix(attributeNode.Prefix) != attributeNode.NamespaceURI &&\r
+ attributeNode.Prefix != "xmlns")\r
+ w.WriteAttributeString("xmlns", attributeNode.Prefix, "http://www.w3.org/2000/xmlns/", attributeNode.NamespaceURI);
}
WriteContentTo(w);
- // indent (linefeeding)
- if(!OwnerDocument.PreserveWhitespace && w.XmlSpace != XmlSpace.Preserve)
- w.WriteWhitespace("\n");
-
w.WriteEndElement();
}