[sgen] Restore hazard pointers in suspend signal handler. Fixes #15695.
[mono.git] / mcs / class / System.XML / Mono.Xml.XPath / XPathEditableDocument.cs
index d7a008ebcfb0aa854710b866330901d4a5339a7b..1c21cae56243233a0ac587c61787e25b13519841 100644 (file)
@@ -206,7 +206,20 @@ namespace Mono.Xml.XPath
 
                public override void WriteRaw (string raw)
                {
-                       throw new NotSupportedException ();
+                       XmlReader reader = new XmlTextReader(new System.IO.StringReader(raw));
+                       WriteRaw(reader);
+               }
+
+               private void WriteRaw(XmlReader reader)
+               {
+                       if (reader != null && reader.NodeType == XmlNodeType.Element)
+                       {
+                               WriteStartElement (reader.Prefix, reader.LocalName, reader.NamespaceURI);
+                               WriteAttributes (reader, true);
+                               WriteRaw (reader.ReadSubtree ());
+                               WriteEndElement ();
+
+                       }
                }
 
                public override void WriteSurrogateCharEntity (char msb, char lsb)
@@ -253,7 +266,10 @@ namespace Mono.Xml.XPath
 
                public override void WriteEndAttribute ()
                {
-                       XmlElement element = current as XmlElement;
+                       // when the writer is for AppendChild() and the root 
+                       // node is element, it allows to write attributes
+                       // (IMHO incorrectly: isn't it append "child" ???)
+                       XmlElement element = (current as XmlElement) ?? (nextSibling == null ? parent as XmlElement : null);
                        if (state != WriteState.Attribute || element == null)
                                throw new InvalidOperationException ("Current state is not inside attribute. Cannot close attribute.");
                        element.SetAttributeNode (attribute);
@@ -494,6 +510,18 @@ namespace Mono.Xml.XPath
                        get { return navigator.Value; }
                }
 
+               public override string XmlLang {
+                       get { return navigator.XmlLang; }
+               }
+
+               public override bool HasChildren {
+                       get { return navigator.HasChildren; }
+               }
+
+               public override bool HasAttributes {
+                       get { return navigator.HasAttributes; }
+               }
+
                public override XPathNavigator Clone ()
                {
                        return new XmlDocumentEditableNavigator (this);
@@ -501,7 +529,7 @@ namespace Mono.Xml.XPath
 
                public override XPathNavigator CreateNavigator ()
                {
-                       return navigator.Clone ();
+                       return Clone ();
                }
 
                public XmlNode GetNode ()
@@ -664,11 +692,18 @@ namespace Mono.Xml.XPath
                public override void DeleteSelf ()
                {
                        XmlNode n = ((IHasXmlNode) navigator).GetNode ();
-                       if (!navigator.MoveToNext ())
+                       XmlAttribute a = n as XmlAttribute;
+                       if (a != null) {
+                               if (a.OwnerElement == null)
+                                       throw new InvalidOperationException ("This attribute node cannot be removed since it has no owner element.");
                                navigator.MoveToParent ();
-                       if (n.ParentNode == null)
-                               throw new InvalidOperationException ("This node cannot be removed since it has no parent.");
-                       n.ParentNode.RemoveChild (n);
+                               a.OwnerElement.RemoveAttributeNode (a);
+                       } else {
+                               if (n.ParentNode == null)
+                                       throw new InvalidOperationException ("This node cannot be removed since it has no parent.");
+                               navigator.MoveToParent ();
+                               n.ParentNode.RemoveChild (n);
+                       }
                }
 
                public override void ReplaceSelf (XmlReader reader)
@@ -718,6 +753,54 @@ namespace Mono.Xml.XPath
                                n.RemoveChild (n.FirstChild);
                        n.InnerText = value;
                }
+
+               public override void MoveToRoot ()
+               {
+                       navigator.MoveToRoot ();
+               }
+
+               public override bool MoveToNamespace (string name)
+               {
+                       return navigator.MoveToNamespace (name);
+               }
+
+               public override bool MoveToFirst ()
+               {
+                       return navigator.MoveToFirst ();
+               }
+
+               public override bool MoveToAttribute (string localName, string namespaceURI)
+               {
+                       return navigator.MoveToAttribute (localName, namespaceURI);
+               }
+
+               public override bool IsDescendant (XPathNavigator nav)
+               {
+                       XmlDocumentEditableNavigator e = nav as XmlDocumentEditableNavigator;
+                       if (e != null)
+                               return navigator.IsDescendant (e.navigator);
+                       else
+                               return navigator.IsDescendant (nav);
+               }
+
+               public override string GetNamespace (string name)
+               {
+                       return navigator.GetNamespace (name);
+               }
+
+               public override string GetAttribute (string localName, string namespaceURI)
+               {
+                       return navigator.GetAttribute (localName, namespaceURI);
+               }
+
+               public override XmlNodeOrder ComparePosition (XPathNavigator nav)
+               {
+                       XmlDocumentEditableNavigator e = nav as XmlDocumentEditableNavigator;
+                       if (e != null)
+                               return navigator.ComparePosition (e.navigator);
+                       else
+                               return navigator.ComparePosition (nav);
+               }
        }
 }