X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.XML%2FSystem.Xml%2FXmlNode.cs;h=d4d39a77aef518963f4a3e34284010eeb8e3f7b9;hb=07aae53facdf9b4f8fe011bf0add6b7bda4560fe;hp=48744fad3c81f8879d3ce3ea7ca3f45c16044a81;hpb=4d82c52aebf33ced1d8b934323eccbb905419a9e;p=mono.git diff --git a/mcs/class/System.XML/System.Xml/XmlNode.cs b/mcs/class/System.XML/System.Xml/XmlNode.cs index 48744fad3c8..d4d39a77aef 100644 --- a/mcs/class/System.XML/System.Xml/XmlNode.cs +++ b/mcs/class/System.XML/System.Xml/XmlNode.cs @@ -40,10 +40,9 @@ namespace System.Xml get { return null; } } - [MonoTODO] public virtual string BaseURI { - get { throw new NotImplementedException (); } + get { return ParentNode.BaseURI; } } public virtual XmlNodeList ChildNodes { @@ -78,12 +77,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; } @@ -198,9 +198,15 @@ namespace System.Xml public virtual XmlNode AppendChild (XmlNode newChild) { - if (NodeType == XmlNodeType.Document - || NodeType == XmlNodeType.Element - || NodeType == XmlNodeType.Attribute) { + XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument; + + ownerDoc.onNodeInserting (newChild, this); + + if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute) { + + if (newChild.OwnerDocument != ownerDoc) + throw new ArgumentException ("Can't append a node created by another document."); + XmlLinkedNode newLinkedChild = (XmlLinkedNode) newChild; XmlLinkedNode lastLinkedChild = LastLinkedChild; @@ -214,6 +220,8 @@ namespace System.Xml LastLinkedChild = newLinkedChild; + ownerDoc.onNodeInserted (newChild, newChild.ParentNode); + return newChild; } else throw new InvalidOperationException(); @@ -228,7 +236,7 @@ namespace System.Xml public abstract XmlNode CloneNode (bool deep); [MonoTODO] - public virtual XPathNavigator CreateNavigator () + public XPathNavigator CreateNavigator () { return new XmlDocumentNavigator(this); } @@ -286,11 +294,17 @@ namespace System.Xml public virtual void RemoveAll () { + XmlDocument ownerDoc = (NodeType == XmlNodeType.Document) ? (XmlDocument)this : OwnerDocument; + + ownerDoc.onNodeRemoving (this, this.ParentNode); LastLinkedChild = null; + ownerDoc.onNodeRemoved (this, this.ParentNode); } public virtual XmlNode RemoveChild (XmlNode oldChild) { + OwnerDocument.onNodeRemoving (oldChild, oldChild.ParentNode); + if (NodeType == XmlNodeType.Document || NodeType == XmlNodeType.Element || NodeType == XmlNodeType.Attribute) { if (IsReadOnly) @@ -312,6 +326,8 @@ namespace System.Xml oldLinkedChild.NextLinkedSibling = null; } + OwnerDocument.onNodeRemoved (oldChild, oldChild.ParentNode); + return oldChild; } else @@ -324,28 +340,43 @@ namespace System.Xml throw new NotImplementedException (); } - [MonoTODO] public XmlNodeList SelectNodes (string xpath) { - throw new NotImplementedException (); + return SelectNodes (xpath, null); } [MonoTODO] public XmlNodeList SelectNodes (string xpath, XmlNamespaceManager nsmgr) { - throw new NotImplementedException (); + XPathNavigator nav = CreateNavigator (); + XPathExpression expr = nav.Compile (xpath); + if (nsmgr != null) + expr.SetContext (nsmgr); + XPathNodeIterator iter = nav.Select (expr); + ArrayList rgNodes = new ArrayList (); + while (iter.MoveNext ()) + { + rgNodes.Add (((XmlDocumentNavigator) iter.Current).Node); + } + return new XmlNodeArrayList (rgNodes); } - [MonoTODO] public XmlNode SelectSingleNode (string xpath) { - throw new NotImplementedException (); + return SelectSingleNode (xpath, null); } [MonoTODO] public XmlNode SelectSingleNode (string xpath, XmlNamespaceManager nsmgr) { - throw new NotImplementedException (); + XPathNavigator nav = CreateNavigator (); + XPathExpression expr = nav.Compile (xpath); + if (nsmgr != null) + expr.SetContext (nsmgr); + XPathNodeIterator iter = nav.Select (expr); + if (!iter.MoveNext ()) + return null; + return ((XmlDocumentNavigator) iter.Current).Node; } internal void SetParentNode (XmlNode parent)