X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.XML%2FSystem.Xml%2FXmlNode.cs;h=29914148f4f677693c77fc37f8ba02ee3ae75565;hb=2a6da5d6f1e6d02f0e3595b3a02af6cacea2772c;hp=59a5c752aa4603cd041fbcf18c3f72828668a836;hpb=c004fb18995530e4b6d221e0024fc78724b5063b;p=mono.git diff --git a/mcs/class/System.XML/System.Xml/XmlNode.cs b/mcs/class/System.XML/System.Xml/XmlNode.cs index 59a5c752aa4..29914148f4f 100644 --- a/mcs/class/System.XML/System.Xml/XmlNode.cs +++ b/mcs/class/System.XML/System.Xml/XmlNode.cs @@ -3,8 +3,10 @@ // // Author: // Kral Ferch +// Atsushi Enomoto // // (C) 2002 Kral Ferch +// (C) 2002 Atsushi Enomoto // using System; @@ -35,19 +37,21 @@ namespace System.Xml #region Properties - public virtual XmlAttributeCollection Attributes - { + public virtual XmlAttributeCollection Attributes { get { return null; } } - public virtual string BaseURI - { - get { return ParentNode.BaseURI; } + public virtual string BaseURI { + get { + // Isn't it conformant to W3C XML Base Recommendation? + // As far as I tested, there are not... + return (ParentNode != null) ? ParentNode.BaseURI : OwnerDocument.BaseURI; + } } public virtual XmlNodeList ChildNodes { get { - return new XmlNodeListChildren(this); + return new XmlNodeListChildren (this); } } @@ -66,7 +70,7 @@ namespace System.Xml get { return LastChild != null; } } - [MonoTODO] + [MonoTODO("confirm whether this way is right for each not-overriden types.")] public virtual string InnerText { get { StringBuilder builder = new StringBuilder (); @@ -77,12 +81,13 @@ namespace System.Xml set { throw new NotImplementedException (); } } - private void AppendChildValues(XmlNode parent, StringBuilder builder) + private void AppendChildValues (XmlNode parent, StringBuilder builder) { XmlNode node = parent.FirstChild; while (node != null) { - builder.Append (node.Value); + if (node.NodeType == XmlNodeType.Text) + builder.Append (node.Value); AppendChildValues (node, builder); node = node.NextSibling; } @@ -94,9 +99,9 @@ namespace System.Xml StringWriter sw = new StringWriter (); XmlTextWriter xtw = new XmlTextWriter (sw); - WriteContentTo(xtw); + WriteContentTo (xtw); - return sw.GetStringBuilder().ToString(); + return sw.GetStringBuilder ().ToString (); } set { throw new NotImplementedException (); } @@ -158,14 +163,20 @@ namespace System.Xml public abstract XmlNodeType NodeType { get; } + internal virtual XPathNodeType XPathNodeType { + get { + return (XPathNodeType) (-1); + } + } + public virtual string OuterXml { get { StringWriter sw = new StringWriter (); XmlTextWriter xtw = new XmlTextWriter (sw); - WriteTo(xtw); + WriteTo (xtw); - return sw.GetStringBuilder().ToString(); + return sw.GetStringBuilder ().ToString (); } } @@ -191,62 +202,75 @@ namespace System.Xml set { throw new InvalidOperationException ("This node does not have a value"); } } + internal virtual string XmlLang { + get { + if(Attributes != null) + foreach(XmlAttribute attr in Attributes) + if(attr.Name == "xml:lang") + return attr.Value; + return (ParentNode != null) ? ParentNode.XmlLang : OwnerDocument.XmlLang; + } + } + + internal virtual XmlSpace XmlSpace { + get { + if(Attributes != null) { + foreach(XmlAttribute attr in Attributes) { + if(attr.Name == "xml:space") { + switch(attr.Value) { + case "preserve": return XmlSpace.Preserve; + case "default": return XmlSpace.Default; + } + break; + } + } + } + return (ParentNode != null) ? ParentNode.XmlSpace : OwnerDocument.XmlSpace; + } + } + #endregion #region Methods public virtual XmlNode AppendChild (XmlNode newChild) { - if (NodeType == XmlNodeType.Document - || NodeType == XmlNodeType.Element - || NodeType == XmlNodeType.Attribute) { - XmlLinkedNode newLinkedChild = (XmlLinkedNode) newChild; - XmlLinkedNode lastLinkedChild = LastLinkedChild; - - newLinkedChild.parentNode = this; - - if (lastLinkedChild != null) { - newLinkedChild.NextLinkedSibling = lastLinkedChild.NextLinkedSibling; - lastLinkedChild.NextLinkedSibling = newLinkedChild; - } else - newLinkedChild.NextLinkedSibling = newLinkedChild; - - LastLinkedChild = newLinkedChild; - - return newChild; - } else - throw new InvalidOperationException(); + // I assume that AppendChild(n) equals to InsertAfter(n, this.LastChild) or InsertBefore(n, null) + return InsertBefore (newChild, null); } - [MonoTODO] public virtual XmlNode Clone () { - throw new NotImplementedException (); + // By MS document, it is equivalent to CloneNode(true). + return this.CloneNode (true); } public abstract XmlNode CloneNode (bool deep); [MonoTODO] - public virtual XPathNavigator CreateNavigator () + public XPathNavigator CreateNavigator () { - return new XmlDocumentNavigator(this); + return new XmlDocumentNavigator (this); } public IEnumerator GetEnumerator () { - return new XmlNodeListChildren(this).GetEnumerator(); + return new XmlNodeListChildren (this).GetEnumerator (); } - [MonoTODO] + [MonoTODO("performance problem.")] public virtual string GetNamespaceOfPrefix (string prefix) { - throw new NotImplementedException (); + XmlNamespaceManager nsmgr = ConstructNamespaceManager (); + return nsmgr.LookupNamespace (prefix); } - [MonoTODO] + [MonoTODO("performance problem.")] public virtual string GetPrefixOfNamespace (string namespaceURI) { - throw new NotImplementedException (); + XmlNamespaceManager nsmgr = ConstructNamespaceManager (); + string ns = nsmgr.LookupPrefix (namespaceURI); + return (ns != null) ? ns : String.Empty; } object ICloneable.Clone () @@ -259,16 +283,97 @@ namespace System.Xml return GetEnumerator (); } - [MonoTODO] public virtual XmlNode InsertAfter (XmlNode newChild, XmlNode refChild) { - throw new NotImplementedException (); + // I assume that insertAfter(n1, n2) equals to InsertBefore(n1, n2.PreviousSibling). + + // I took this way because rather than calling InsertAfter() from InsertBefore() + // because current implementation of 'NextSibling' looks faster than 'PreviousSibling'. + XmlNode argNode = null; + if(refChild != null) + argNode = refChild.NextSibling; + else if(ChildNodes.Count > 0) + argNode = FirstChild; + return InsertBefore (newChild, argNode); } - [MonoTODO] + [MonoTODO("If inserted node is entity reference, then check conforming entity. Wait for DTD implementation.")] public virtual XmlNode InsertBefore (XmlNode newChild, XmlNode refChild) { - throw new NotImplementedException (); + XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument; + + if (NodeType == XmlNodeType.Document || + NodeType == XmlNodeType.Element || + NodeType == XmlNodeType.Attribute || + NodeType == XmlNodeType.DocumentFragment) { + if (IsReadOnly) + throw new ArgumentException ("The specified node is readonly."); + + if (newChild.OwnerDocument != ownerDoc) + throw new ArgumentException ("Can't append a node created by another document."); + + if (refChild != null && newChild.OwnerDocument != refChild.OwnerDocument) + throw new ArgumentException ("argument nodes are on the different documents."); + + // This check is done by MS.NET 1.0, but isn't done for MS.NET 1.1. + // Skip this check in the meantime... +// if(this == ownerDoc && ownerDoc.DocumentElement != null && (newChild is XmlElement)) +// throw new XmlException ("multiple document element not allowed."); + + // checking validity finished. then appending... + + ownerDoc.onNodeInserting (newChild, this); + + if(newChild.ParentNode != null) + newChild.ParentNode.RemoveChild (newChild); + + if(newChild.NodeType == XmlNodeType.DocumentFragment) { + int x = newChild.ChildNodes.Count; + for(int i=0; i