X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.XML%2FSystem.Xml%2FXmlElement.cs;h=8ba8f30946c13a807193383095dbdfd97e9d1da3;hb=879d8fbdcd1e6a59972d878a74760a0d67055062;hp=9e89c4c51b5b846f8647105a1e0ead15305126ce;hpb=1c54369275b4c5371470e7f6a34a8c21378b9855;p=mono.git diff --git a/mcs/class/System.XML/System.Xml/XmlElement.cs b/mcs/class/System.XML/System.Xml/XmlElement.cs index 9e89c4c51b5..8ba8f30946c 100644 --- a/mcs/class/System.XML/System.Xml/XmlElement.cs +++ b/mcs/class/System.XML/System.Xml/XmlElement.cs @@ -3,13 +3,16 @@ // // 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 @@ -22,6 +25,7 @@ namespace System.Xml private string localName; private string namespaceURI; private string prefix; + private bool isEmpty; #endregion @@ -83,23 +87,31 @@ namespace System.Xml 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] public bool IsEmpty { - get { throw new NotImplementedException (); } + get { return isEmpty; } - set { throw new NotImplementedException (); } + set { + if(value) { + RemoveAll(); + } + isEmpty = value; + } } public override string LocalName { @@ -351,37 +363,21 @@ namespace System.Xml w.WriteStartElement(Prefix, LocalName, NamespaceURI); // write namespace declarations(if not exist) - if(Prefix != null && w.LookupPrefix(Prefix) != NamespaceURI) + if(Prefix != null && Prefix != String.Empty && 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) + if(attributeNode.Prefix != null && attributeNode.Prefix != String.Empty && + w.LookupPrefix(attributeNode.Prefix) != attributeNode.NamespaceURI && + attributeNode.Prefix != "xmlns") 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()); - } - WriteContentTo(w); - // indent (linefeeding) - if(!OwnerDocument.PreserveWhitespace && w.XmlSpace != XmlSpace.Preserve) - w.WriteWhitespace("\n"); - w.WriteEndElement(); }