diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2005-12-08 11:40:59 +0300 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2005-12-08 11:40:59 +0300 |
commit | fff797f63f9fa119a03d499d0ef2d9736c4e5ace (patch) | |
tree | 83d107cf6d92dcfbdc2a6d6377a91dba814431d3 /mcs/class/System.XML | |
parent | acdcd911d43de83682094b1e2243dcc421d2a605 (diff) |
2005-12-08 Atsushi Enomoto <atsushi@ximian.com>
* XPathDocument2.cs, XPathDocument2Editable.cs,
XPathDocument2Navigator.cs : garbage cleanup.
svn path=/trunk/mcs/; revision=54101
Diffstat (limited to 'mcs/class/System.XML')
4 files changed, 5 insertions, 2456 deletions
diff --git a/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog b/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog index 8b2787a0b6a..dfa7fae3b31 100644 --- a/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog +++ b/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog @@ -1,3 +1,8 @@ +2005-12-08 Atsushi Enomoto <atsushi@ximian.com> + + * XPathDocument2.cs, XPathDocument2Editable.cs, + XPathDocument2Navigator.cs : garbage cleanup. + 2005-08-05 Atsushi Enomoto <atsushi@ximian.com> * Pattern.cs, IdPattern.cs, LocationPathPattern.cs, UnionPattern.cs : diff --git a/mcs/class/System.XML/Mono.Xml.XPath/XPathDocument2.cs b/mcs/class/System.XML/Mono.Xml.XPath/XPathDocument2.cs deleted file mode 100644 index c50ede67c69..00000000000 --- a/mcs/class/System.XML/Mono.Xml.XPath/XPathDocument2.cs +++ /dev/null @@ -1,1188 +0,0 @@ -//
-// Mono.Xml.XPath.XPathDocument2.cs
-//
-// Author:
-// Atsushi Enomoto <atsushi@ximian.com>
-//
-// (C)2004 Novell Inc.
-//
-// Another Document tree model.
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-#if NET_2_0
-using System;
-using System.Collections;
-using System.Collections.Specialized;
-using System.IO;
-using System.Text;
-using System.Xml;
-using System.Xml.XPath;
-
-namespace Mono.Xml.XPath
-{
-
-/*
- public class Driver
- {
- public static void Main ()
- {
- try {
- DateTime start = DateTime.Now;
- Console.WriteLine (DateTime.Now.Ticks);
-#if false
- XmlDocument doc = new XmlDocument ();
- doc.PreserveWhitespace = true;
- doc.Load (new XmlTextReader ("../TestResult.xml"));
-#else
- XPathDocument2 doc = new XPathDocument2 ();
- doc.Load (new XmlTextReader ("../TestResult.xml"));
-// XPathDocument doc = new XPathDocument ("../TestResult.xml", XmlSpace.Preserve);
-// XPathDocument doc = new XPathDocument ("test.xml", XmlSpace.Preserve);
-#endif
-// doc.Load (new XmlTextReader ("test.xml"));
-
-// doc.WriteTo (new XmlTextWriter (Console.Out));
-//return;
- Console.WriteLine (DateTime.Now.Ticks);
-
- XPathNavigator nav = doc.CreateNavigator ();
-//Console.WriteLine (nav.MoveToFirstChild ());
-//Console.WriteLine (nav.LocalName + nav.NodeType);
-//Console.WriteLine (nav.MoveToNext ());
-//Console.WriteLine (nav.LocalName + nav.NodeType);
-//Console.WriteLine (nav.MoveToNext ());
-//Console.WriteLine (nav.LocalName + nav.NodeType);
-//Console.WriteLine (nav.MoveToNext ());
-//Console.WriteLine (nav.LocalName + nav.NodeType);
-//nav.MoveToRoot ();
-
-
- XmlReader reader = nav.ReadSubtree ();
- XmlTextWriter w = new XmlTextWriter (new StringWriter ());
-// XmlTextWriter w = new XmlTextWriter (Console.Out);
- w.WriteNode (reader, false);
- Console.WriteLine (DateTime.Now.Ticks);
- Console.WriteLine (DateTime.Now.Ticks - start.Ticks);
- } catch (Exception ex) {
- Console.WriteLine (ex);
- }
- }
- }
-*/
-
- // Wrapper
-
- public class XPathDocument2 : IXPathNavigable
- {
- XomRoot root;
-
- public XPathDocument2 ()
- : this (new NameTable ())
- {
- }
-
- public XPathDocument2 (XmlNameTable nameTable)
- {
- root = new XomRoot (nameTable);
- }
-
- public XmlNameTable NameTable {
- get { return root.NameTable; }
- }
-
- public void LoadXml (string xml)
- {
- Load (new XmlTextReader (xml, XmlNodeType.Document, null));
- }
-
- public void Load (TextReader reader)
- {
- Load (new XmlTextReader (reader));
- }
-
- public void Load (XmlReader reader)
- {
- Load (reader, XmlSpace.None);
- }
-
- public void Load (XmlReader reader, XmlSpace space)
- {
- root.Load (reader, space);
- }
-
- public void Save (TextWriter writer)
- {
- XmlTextWriter xtw = new XmlTextWriter (writer);
- xtw.Formatting = Formatting.Indented;
- WriteTo (xtw);
- }
-
- public void Save (XmlWriter writer)
- {
- WriteTo (writer);
- }
-
- public void WriteTo (XmlWriter writer)
- {
- root.WriteTo (writer);
- }
-
- public XPathNavigator CreateNavigator ()
- {
- return new XomNavigator (root);
- }
- }
-
- // Xom part
-
- public struct XmlName
- {
- public string Prefix;
- public string LocalName;
- public string Namespace;
- string fullName;
-
- public XmlName (string prefix, string name, string ns)
- {
- this.Prefix = prefix == null ? "" : prefix;
- this.LocalName = name;
- this.Namespace = ns == null ? "" : ns;
- fullName = null;
- }
-
- public override bool Equals (object o)
- {
- if ( !(o is XmlName))
- return false;
- XmlName other = (XmlName) o;
- return LocalName == other.LocalName && Namespace == other.Namespace;
- }
-
- public static bool operator == (XmlName n1, XmlName n2)
- {
- return n1.LocalName == n2.LocalName && n1.Namespace == n2.Namespace;
- }
-
- public static bool operator != (XmlName n1, XmlName n2)
- {
- return n1.LocalName != n2.LocalName || n1.Namespace != n2.Namespace;
- }
-
- public override int GetHashCode ()
- {
- if (fullName == null)
- fullName = String.Concat (LocalName, "/", Namespace);
- return fullName.GetHashCode ();
- }
-
- public override string ToString ()
- {
- if (fullName == null)
- fullName = String.Concat (LocalName, "/", Namespace);
- return fullName;
- }
- }
-
- public abstract class XomNode
- {
- XomParentNode parent;
- string prefixedName;
- XomNode previousSibling;
- XomNode nextSibling;
-
- public XomRoot Root {
- get {
- XomNode n = this;
- while (n.parent != null)
- n = n.parent;
- return (XomRoot) n;
- }
- }
-
- public string PrefixedName {
- get {
- if (prefixedName == null) {
- if (Prefix.Length > 0)
- prefixedName = Prefix + ':' + LocalName;
- else
- prefixedName = LocalName;
- }
- return prefixedName;
- }
- }
-
- public virtual string BaseURI {
- get { return Root.BaseURI; }
- }
-
- public virtual string XmlLang {
- get { return String.Empty; }
- }
-
- public XomParentNode Parent {
- get { return parent; }
- }
-
- public XomNode PreviousSibling {
- get { return previousSibling; }
- }
-
- public XomNode NextSibling {
- get { return nextSibling; }
- }
-
- internal void SetParent (XomParentNode parent)
- {
- this.parent = parent;
- }
-
- internal void SetPreviousSibling (XomNode previous)
- {
- if (previous.parent != parent || this == previous)
- throw new InvalidOperationException ();
- nextSibling = previous.nextSibling;
- previousSibling = previous;
- previous.nextSibling = this;
- }
-
- internal void SetNextSibling (XomNode next)
- {
- if (next.parent != parent || this == next)
- throw new InvalidOperationException ();
- previousSibling = next.previousSibling;
- nextSibling = next;
- next.previousSibling = this;
- }
-
- internal void RemoveItself ()
- {
- if (previousSibling != null)
- previousSibling.nextSibling = nextSibling;
- if (nextSibling != null)
- nextSibling.previousSibling = previousSibling;
- parent = null;
- }
-
- public string LookupPrefix (string ns)
- {
- XomElement n = this as XomElement;
- if (n == null)
- n = Parent as XomElement;
- while (n != null) {
- int len = n.NamespaceCount;
- for (int i = 0; i < len; i++) {
- XomNamespace nn = n.GetLocalNamespace (i);
- if (nn.Value == ns)
- return nn.LocalName;
- }
- }
- return null;
- }
-
- public string LookupNamespace (string ns)
- {
- XomElement n = this as XomElement;
- if (n == null)
- n = Parent as XomElement;
- while (n != null) {
- int len = n.NamespaceCount;
- for (int i = 0; i < len; i++) {
- XomNamespace nn = n.GetLocalNamespace (i);
- if (nn.Namespace== ns)
- return nn.Prefix;
- }
- }
- return null;
- }
-
- public virtual bool IsEmptyElement {
- get { return false; }
- }
-
- public abstract string LocalName { get; }
-
- public abstract string Namespace { get; }
-
- public abstract string Prefix { get; }
-
- public abstract string Value { get; set; }
-
- public abstract XPathNodeType NodeType { get; }
-
- public abstract int ChildCount { get; }
-
- public virtual XomNode FirstChild { get { return null; } }
-
- public virtual XomNode LastChild { get { return null; } }
-
- internal abstract void BuildValue (StringBuilder sb);
-
- public string OuterXml {
- get {
- StringWriter sw = new StringWriter ();
- XmlTextWriter xtw = new XmlTextWriter (sw);
- WriteTo (xtw);
- return sw.ToString ();
- }
- }
-
- public string InnerXml {
- get {
- StringWriter sw = new StringWriter ();
- XmlTextWriter xtw = new XmlTextWriter (sw);
- for (XomNode n = FirstChild; n != null; n = n.NextSibling)
- n.WriteTo (xtw);
- return sw.ToString ();
- }
- }
-
- public abstract void WriteTo (XmlWriter writer);
- }
-
- public interface IHasXomNode
- {
- XomNode GetNode ();
- }
-
- public abstract class XomParentNode : XomNode
- {
- XomNode firstChild;
- XomNode lastChild;
- int childCount;
-
- public void ReadNode (XmlReader reader, XmlSpace space)
- {
- switch (reader.ReadState) {
- case ReadState.Initial:
- reader.Read ();
- break;
- case ReadState.Error:
- case ReadState.Closed:
- case ReadState.EndOfFile:
- throw new ArgumentException ("Argument XmlReader is not readable.");
- }
-
- switch (reader.NodeType) {
- case XmlNodeType.Element:
- XomElement el = new XomElement (reader.Prefix, reader.LocalName, reader.NamespaceURI, this);
- if (reader.MoveToFirstAttribute ()) {
- do {
- new XomAttribute (reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.Value, el);
- } while (reader.MoveToNextAttribute ());
- reader.MoveToContent ();
- }
- if (reader.IsEmptyElement) {
- el.SetIsEmpty (true);
- reader.Read ();
- }
- else {
- reader.Read ();
- while (reader.NodeType != XmlNodeType.EndElement)
- el.ReadNode (reader, space);
- reader.ReadEndElement ();
- }
- return;
- case XmlNodeType.Text:
- case XmlNodeType.CDATA:
- XomText text = new XomText (reader.Value, this);
- reader.Read ();
- return;
- case XmlNodeType.SignificantWhitespace:
- XomSignificantWhitespace sws = new XomSignificantWhitespace (reader.Value, this);
- reader.Read ();
- return;
- case XmlNodeType.Whitespace:
- if (space == XmlSpace.Default) {
- reader.Skip ();
- return;
- }
- XomWhitespace ws = new XomWhitespace (reader.Value, this);
- reader.Read ();
- return;
- case XmlNodeType.ProcessingInstruction:
- XomPI pi = new XomPI (reader.LocalName, reader.Value, this);
- reader.Read ();
- return;
- case XmlNodeType.Comment:
- XomComment comment = new XomComment (reader.Value, this);
- reader.Read ();
- return;
- default:
- reader.Skip ();
- return;
- }
- }
-
- public void AppendChild (XomNode child)
- {
- InsertBefore (child, null);
- }
-
- public void InsertBefore (XomNode child, XomNode nextNode)
- {
- if (child.Parent != null)
- throw new InvalidOperationException ("The child already has a parent.");
- if (nextNode == null) {
- child.SetParent (this);
- if (firstChild == null)
- firstChild = lastChild = child;
- else {
- child.SetPreviousSibling (lastChild);
- lastChild = child;
- }
- } else {
- if (nextNode.Parent != this)
- throw new ArgumentException ("Argument nextNode is not a child of this node.");
- child.SetNextSibling (nextNode);
- }
- childCount++;
- }
-
- public abstract void Clear ();
-
- public override XomNode FirstChild {
- get { return firstChild; }
- }
-
- public override XomNode LastChild {
- get { return lastChild; }
- }
-
- public override int ChildCount {
- get { return childCount; }
- }
-
- internal void ClearChildren ()
- {
- firstChild = lastChild = null;
- childCount = 0;
- }
-
- public void RemoveChild (XomNode child)
- {
- if (child == firstChild)
- firstChild = child.NextSibling;
- if (child == lastChild)
- lastChild = child.PreviousSibling;
- child.RemoveItself ();
- childCount--;
- }
-
- public override string Value {
- get {
- StringBuilder sb = new StringBuilder ();
- BuildValue (sb);
- return sb.ToString ();
- }
- set {
- ClearChildren ();
- AppendChild (new XomText (value));
- }
- }
-
- internal override void BuildValue (StringBuilder sb)
- {
- for (XomNode n = FirstChild; n != null; n = n.NextSibling)
- n.BuildValue (sb);
- }
- }
-
- public class XomRoot : XomParentNode
- {
- XmlNameTable nameTable;
- Hashtable identicalElements;
- string baseUri;
-
- public XomRoot (XmlNameTable nameTable)
- {
- this.nameTable = nameTable;
- identicalElements = new Hashtable ();
- }
-
- public override string BaseURI {
- get { return baseUri; }
- }
-
- public void Load (XmlReader reader)
- {
- Load (reader, XmlSpace.None);
- }
-
- public void Load (XmlReader reader, XmlSpace space)
- {
- baseUri = reader.BaseURI;
- while (!reader.EOF)
- ReadNode (reader, space);
- }
-
- public XmlNameTable NameTable {
- get { return nameTable; }
- }
-
- public override string Prefix {
- get { return ""; }
- }
-
- public override string LocalName {
- get { return ""; }
- }
-
- public override string Namespace {
- get { return ""; }
- }
-
- public override XPathNodeType NodeType {
- get { return XPathNodeType.Root; }
- }
-
- public override void Clear ()
- {
- ClearChildren ();
- }
-
- public override void WriteTo (XmlWriter writer)
- {
- for (XomNode n = FirstChild; n != null; n = n.NextSibling)
- n.WriteTo (writer);
- }
-
- public XomElement GetIdenticalNode (string id)
- {
- return identicalElements [id] as XomElement;
- }
-
- internal void GetIdenticalNode (string id, XomElement element)
- {
- identicalElements.Add (id, element);
- }
- }
-
- public class XomElement : XomParentNode
- {
- XmlName qname;
- bool isEmptyElement;
-
- ArrayList attributes;
- ArrayList namespaces;
-
- public XomElement (string name)
- : this ("", name, "", null)
- {
- }
-
- public XomElement (string name, XomRoot root)
- : this ("", name, "", root)
- {
- }
-
- public XomElement (string name, string ns)
- : this ("", name, ns, null)
- {
- }
-
- public XomElement (string name, string ns, XomRoot root)
- : this ("", name, ns, root)
- {
- }
-
- public XomElement (string prefix, string name, string ns)
- : this (prefix, name, ns, null)
- {
- }
-
- public XomElement (string prefix, string name, string ns, XomParentNode parent)
- {
- qname.LocalName = name;
- qname.Namespace = ns == null ? "" : ns;
- qname.Prefix = prefix == null ? "" : prefix;
- if (parent != null)
- parent.AppendChild (this);
- }
-
- public override bool IsEmptyElement {
- get { return isEmptyElement; }
- }
-
- internal void SetIsEmpty (bool value)
- {
- isEmptyElement = value;
- }
-
- public override string Prefix {
- get { return qname.Prefix; }
- }
-
- public override string LocalName {
- get { return qname.LocalName; }
- }
-
- public override string Namespace {
- get { return qname.Namespace; }
- }
-
- public override XPathNodeType NodeType {
- get { return XPathNodeType.Element; }
- }
-
- public override void Clear ()
- {
- if (attributes != null)
- attributes.Clear ();
- if (namespaces != null)
- namespaces.Clear ();
- ClearChildren ();
- }
-
- public void AppendAttribute (XomAttribute attr)
- {
- if (attr.Parent != null)
- throw new InvalidOperationException ("The argument attribute already have another element owner.");
- attr.SetParent (this);
- if (attributes == null)
- attributes = new ArrayList ();
- attributes.Add (attr);
- }
-
-/*
- public void UpdateAttribute (XomAttribute attr)
- {
- if (attr.Parent != null)
- throw new InvalidOperationException ("The argument attribute already have another element owner.");
- XomAttribute existing = GetAttribute (attr.LocalName, attr.Namespace);
- if (existing != null)
- RemoveAttribute (existing);
- if (attributes == null)
- attributes = new ArrayList ();
- attr.SetParent (this);
- attributes.Add (attr);
- }
-*/
-
- public XomAttribute GetAttribute (int index)
- {
- return attributes == null ? null : attributes [index] as XomAttribute;
- }
-
- public XomAttribute GetAttribute (string name, string ns)
- {
- if (attributes == null)
- return null;
- for (int i = 0; i < attributes.Count; i++) {
- XomAttribute a = attributes [i] as XomAttribute;
- if (a.LocalName == name && a.Namespace == ns)
- return a;
- }
- return null;
- }
-
- public XomAttribute GetNextAttribute (XomAttribute attr)
- {
- if (attributes == null || attributes.Count == 0)
- return null;
- if (attributes [attributes.Count - 1] == attr)
- return null;
- // It is not efficient, but usually there won't be so many attributes in an element.
- int index = attributes.IndexOf (attr);
- if (index < 0)
- return null;
- return attributes [index + 1] as XomAttribute;
- }
-
- public int AttributeCount {
- get { return attributes == null ? 0 : attributes.Count; }
- }
-
- public void RemoveAttribute (XomAttribute attr)
- {
- if (attributes == null)
- return;
- attributes.Remove (attr);
- attr.SetParent (null);
- }
-
- public void AppendNamespace (string prefix, string ns)
- {
- if (namespaces == null)
- namespaces = new ArrayList ();
- namespaces.Add (new XomNamespace (prefix, ns));
- }
-
- public XomNamespace GetLocalNamespace (int index)
- {
- if (namespaces == null || namespaces.Count <= index)
- return null;
- return namespaces [index] as XomNamespace;
- }
-
- public XomNamespace GetLocalNamespace (string prefix)
- {
- if (namespaces == null)
- return null;
- for (int i = 0; i < namespaces.Count; i++) {
- XomNamespace qname = namespaces [i] as XomNamespace;
- if (qname.LocalName == prefix)
- return qname;
- }
- return null;
- }
-
- public XomNamespace GetNextLocalNamespace (XomNamespace n)
- {
- if (namespaces == null || namespaces.Count == 0)
- return null;
- if (namespaces [namespaces.Count - 1] == n)
- return null;
- // It is not efficient, but usually there won't be so many attributes in an element.
- int index = namespaces.IndexOf (n);
- if (index < 0)
- return null;
- return namespaces [index + 1] as XomNamespace;
- }
-
- public int NamespaceCount {
- get { return namespaces == null ? 0 : namespaces.Count; }
- }
-
- public void RemoveNamespace (string prefix)
- {
- if (namespaces == null)
- return;
- for (int i = 0; i < namespaces.Count; i++) {
- XomNamespace qname = namespaces [i] as XomNamespace;
- if (qname.LocalName == prefix) {
- namespaces.RemoveAt (i);
- return;
- }
- }
- }
-
- public override void WriteTo (XmlWriter writer)
- {
- writer.WriteStartElement (Prefix, LocalName, Namespace);
- if (namespaces != null) {
- foreach (XomNamespace n in namespaces)
- n.WriteTo (writer);
- }
- if (attributes != null) {
- foreach (XomAttribute a in attributes)
- a.WriteTo (writer);
- }
-
- for (XomNode n = FirstChild; n != null; n = n.NextSibling)
- n.WriteTo (writer);
-
- writer.WriteEndElement ();
- }
- }
-
- public class XomAttribute : XomNode
- {
- XmlName qname;
- string value;
-
- public XomAttribute (string name, string value)
- : this ("", name, "", value, null)
- {
- }
-
- public XomAttribute (string name, string value, XomElement owner)
- : this ("", name, "", value, owner)
- {
- }
-
- public XomAttribute (string name, string ns, string value)
- : this ("", name, ns, value, null)
- {
- }
-
- public XomAttribute (string name, string ns, string value, XomElement owner)
- : this ("", name, ns, value, owner)
- {
- }
-
- public XomAttribute (string prefix, string name, string ns, string value)
- : this ("", name, ns, value, null)
- {
- }
-
- public XomAttribute (string prefix, string name, string ns, string value, XomElement owner)
- {
- qname.LocalName = name;
- qname.Namespace = ns;
- qname.Prefix = prefix;
- this.value = value;
- if (owner != null)
- owner.AppendAttribute (this);
- }
-
- public override string Prefix {
- get { return qname.Prefix; }
- }
-
- public override string LocalName {
- get { return qname.LocalName; }
- }
-
- public override string Namespace {
- get { return qname.Namespace; }
- }
-
- public override XPathNodeType NodeType {
- get { return XPathNodeType.Attribute; }
- }
-
- public override int ChildCount { get { return 0; } }
-
- public override string Value {
- get { return value; }
- set { this.value = value; }
- }
-
- internal override void BuildValue (StringBuilder sb)
- {
- sb.Append (value);
- }
-
- public override void WriteTo (XmlWriter writer)
- {
- writer.WriteAttributeString (Prefix, LocalName, Namespace, Value);
- }
- }
-
- public class XomNamespace : XomNode
- {
- #region static members
- static XomNamespace xml;
-
- static XomNamespace ()
- {
- xml = new XomNamespace ("xml", "http://www.w3.org/XML/1998/namespace");
- }
-
- public static XomNamespace Xml {
- get { return xml; }
- }
- #endregion
-
- XmlName qname;
-
- public XomNamespace (string prefix, string ns)
- {
- qname.LocalName = prefix;
- qname.Namespace = ns;
- }
-
- public override int ChildCount {
- get { return 0; }
- }
-
- public override string LocalName {
- get { return qname.LocalName; }
- }
-
- public override string Prefix {
- get { return LocalName; }
- }
-
- public override string Namespace {
- get { return Value; }
- }
-
- public override string Value {
- get { return qname.Namespace; }
- set { qname.Namespace = value; }
- }
-
- public override XPathNodeType NodeType {
- get { return XPathNodeType.Namespace; }
- }
-
- public override void WriteTo (XmlWriter writer)
- {
- if (LocalName != "")
- writer.WriteAttributeString ("xmlns", LocalName, "http://www.w3.org/2000/xmlns/", Namespace);
- else
- writer.WriteAttributeString ("", "xmlns", "http://www.w3.org/2000/xmlns/", Namespace);
- }
-
- internal override void BuildValue (StringBuilder sb)
- {
- sb.Append (Value);
- }
- }
-
- public class XomComment : XomNode
- {
- string value;
-
- public XomComment (string value)
- : this (value, null)
- {
- }
-
- public XomComment (string value, XomParentNode parent)
- {
- this.value = value;
- if (parent != null)
- parent.AppendChild (this);
- }
-
- public override string Prefix {
- get { return ""; }
- }
-
- public override string LocalName {
- get { return ""; }
- }
-
- public override string Namespace {
- get { return ""; }
- }
-
- public override XPathNodeType NodeType {
- get { return XPathNodeType.Comment; }
- }
-
- public override string Value {
- get { return value; }
- set { this.value += value; }
- }
-
- internal override void BuildValue (StringBuilder sb)
- {
- sb.Append (value);
- }
-
- public override int ChildCount { get { return 0; } }
-
- public override void WriteTo (XmlWriter writer)
- {
- writer.WriteComment (Value);
- }
- }
-
- public class XomPI : XomNode
- {
- string value;
- string name;
-
- public XomPI (string name, string value)
- : this (name, value, null)
- {
- }
-
- public XomPI (string name, string value, XomParentNode parent)
- {
- this.name = name;
- if (value == null)
- value = "";
- this.value = value;
- if (parent != null)
- parent.AppendChild (this);
- }
-
- public override string Prefix {
- get { return ""; }
- }
-
- public override string LocalName {
- get { return name; }
- }
-
- public override string Namespace {
- get { return ""; }
- }
-
- public override XPathNodeType NodeType {
- get { return XPathNodeType.ProcessingInstruction; }
- }
-
- public override string Value {
- get { return value; }
- set { this.value += value; }
- }
-
- internal override void BuildValue (StringBuilder sb)
- {
- sb.Append (value);
- }
-
- public override int ChildCount { get { return 0; } }
-
- public override void WriteTo (XmlWriter writer)
- {
- writer.WriteProcessingInstruction (LocalName, Value);
- }
- }
-
- public class XomText : XomNode
- {
- string value;
-
- public XomText (string value)
- : this (value, null)
- {
- }
-
- public XomText (string value, XomParentNode parent)
- {
- this.value = value;
- if (parent != null)
- parent.AppendChild (this);
- }
-
- public override string Prefix {
- get { return ""; }
- }
-
- public override string LocalName {
- get { return ""; }
- }
-
- public override string Namespace {
- get { return ""; }
- }
-
- public override string Value {
- get { return value; }
- set { this.value += value; }
- }
-
- public override XPathNodeType NodeType {
- get { return XPathNodeType.Text; }
- }
-
- internal override void BuildValue (StringBuilder sb)
- {
- sb.Append (value);
- }
-
- public override int ChildCount { get { return 0; } }
-
- public override void WriteTo (XmlWriter writer)
- {
- writer.WriteString (Value);
- }
- }
-
- public class XomWhitespace : XomNode
- {
- string value;
-
- public XomWhitespace (string value)
- : this (value, null)
- {
- }
-
- public XomWhitespace (string value, XomParentNode parent)
- {
- this.value = value;
- if (parent != null)
- parent.AppendChild (this);
- }
-
- public override string Prefix {
- get { return ""; }
- }
-
- public override string LocalName {
- get { return ""; }
- }
-
- public override string Namespace {
- get { return ""; }
- }
-
- public override string Value {
- get { return value; }
- set { this.value += value; }
- }
-
- public override XPathNodeType NodeType {
- get { return XPathNodeType.Whitespace; }
- }
-
- internal override void BuildValue (StringBuilder sb)
- {
- sb.Append (value);
- }
-
- public override int ChildCount { get { return 0; } }
-
- public override void WriteTo (XmlWriter writer)
- {
- writer.WriteString (Value);
- }
- }
-
- public class XomSignificantWhitespace : XomNode
- {
- string value;
-
- public XomSignificantWhitespace (string value)
- : this (value, null)
- {
- }
-
- public XomSignificantWhitespace (string value, XomParentNode parent)
- {
- this.value = value;
- if (parent != null)
- parent.AppendChild (this);
- }
-
- public override string Prefix {
- get { return ""; }
- }
-
- public override string LocalName {
- get { return ""; }
- }
-
- public override string Namespace {
- get { return ""; }
- }
-
- public override string Value {
- get { return value; }
- set { this.value += value; }
- }
-
- public override XPathNodeType NodeType {
- get { return XPathNodeType.SignificantWhitespace; }
- }
-
- internal override void BuildValue (StringBuilder sb)
- {
- sb.Append (value);
- }
-
- public override int ChildCount { get { return 0; } }
-
- public override void WriteTo (XmlWriter writer)
- {
- writer.WriteString (Value);
- }
- }
-}
-#endif
diff --git a/mcs/class/System.XML/Mono.Xml.XPath/XPathDocument2Editable.cs b/mcs/class/System.XML/Mono.Xml.XPath/XPathDocument2Editable.cs deleted file mode 100644 index ef274ad708b..00000000000 --- a/mcs/class/System.XML/Mono.Xml.XPath/XPathDocument2Editable.cs +++ /dev/null @@ -1,839 +0,0 @@ -// -// Mono.Xml.XPath.XPathDocument2Editable -// -// Author: -// Atsushi Enomoto <atsushi@ximian.com> -// -// (C)2004 Novell Inc. -// -// Yet another implementation of XPathEditableNavigator. -// (Even runnable under MS.NET 2.0) -// - -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -#if NET_2_0 - -using System; -using System.Collections; -using System.ComponentModel; -using System.IO; -using System.Xml; -using System.Xml.Schema; -using System.Xml.XPath; -using System.Xml.Serialization; - -namespace Mono.Xml.XPath -{ -/* - public class Driver - { - public static void Main () - { - try { -#if true - XPathDocument2 doc = new XPathDocument2 (); - XPathDocument2Editable pd = new XPathDocument2Editable (doc); - XPathEditableNavigator nav = pd.CreateEditor (); - IChangeTracking xp = pd; -#else - XPathDocument doc = new XPathDocument (); - XPathEditableNavigator nav = doc.CreateEditor (); - IChangeTracking xp = doc; -#endif - doc.LoadXml ("<root/>"); - nav.MoveToFirstChild (); // root - XmlWriter w = nav.AppendChild (); - Console.WriteLine (((IChangeTracking) xp).IsChanged); - w.WriteElementString ("foo", "foo_text"); - w.WriteElementString ("bar", "bar_text"); - w.WriteStartElement ("hoge"); - w.WriteAttributeString ("fuga", "fugafuga"); - w.WriteAttributeString ("unya", "unyaunya"); - w.WriteFullEndElement (); - w.Close (); - - w = nav.CreateAttributes (); - w.WriteStartAttribute ("namara"); - w.WriteString ("mokera"); - w.WriteEndAttribute (); - w.WriteAttributeString ("beccho", "giccho"); - w.Close (); - - nav.MoveToRoot (); - nav.MoveToFirstChild (); - nav.MoveToFirstChild (); - nav.DeleteCurrent (); // delete foo - Console.WriteLine (nav.Name); - nav.MoveToNext (); - Console.WriteLine (nav.Name); - Console.WriteLine (nav.MoveToFirstAttribute ()); - nav.DeleteCurrent (); // delete fuga - - doc.Save (Console.Out); - } catch (Exception ex) { - Console.WriteLine (ex); - } - } - } -*/ - - public class XPathDocument2Editable - : IXPathNavigable, IXPathEditable, - IRevertibleChangeTracking, IChangeTracking, IXmlSerializable - { - - XPathDocument2 document; - - ArrayList changes = new ArrayList (); - bool enableChangeTracking; - - public XPathDocument2Editable (XPathDocument2 doc) - { - document = doc; - } - -#region Events - - public event NodeChangedEventHandler ChangeRejected; - - public event NodeChangedEventHandler ItemUpdated; - - public event NodeChangedEventHandler ItemUpdating; - - public event NodeChangedEventHandler ItemInserted; - - public event NodeChangedEventHandler ItemInserting; - - public event NodeChangedEventHandler ItemDeleted; - - public event NodeChangedEventHandler ItemDeleting; - - public event NodeChangedEventHandler RejectingChange; - -#endregion // Events - - public XmlNameTable NameTable { - get { return document.NameTable; } - } - - public XPathNavigator CreateNavigator () - { - return document.CreateNavigator (); - } - - public XPathEditableNavigator CreateEditor () - { - return new XomEditableNavigator (this); - } - - public XmlWriter CreateWriter () - { - return CreateEditor ().AppendChild (); - } - - public bool HasChanges () - { - return IsChanged; - } - - public bool EnableChangeTracking { - get { return enableChangeTracking; } - set { enableChangeTracking = value; } - } - - #region IRevertibleChangeTracking/IChangeTracking - public bool IsChanged { - get { return changes.Count != 0; } - } - - public void AcceptChanges () - { - changes.Clear (); - } - - public void RejectChanges () - { - for (int i = changes.Count - 1; i >= 0; i--) { - Insertion2 ins = changes [i] as Insertion2; - if (ins != null) { - ins.ParentNode.RemoveChild (ins.InsertedNode); - continue; - } - - Removal2 rem = changes [i] as Removal2; - if (rem != null) { - if (rem.RemovedNode.NodeType == XPathNodeType.Attribute) { - XomElement el = (XomElement) rem.OwnerNode; - el.AppendAttribute ((XomAttribute) rem.RemovedNode); - } - else - rem.OwnerNode.InsertBefore (rem.RemovedNode, rem.NextSibling); - continue; - } - AttributeUpdate2 au = changes [i] as AttributeUpdate2; - if (au != null) { - au.Element.RemoveAttribute (au.NewAttribute); - if (au.OldAttribute != null) - au.Element.AppendAttribute (au.OldAttribute); - continue; - } - } - changes.Clear (); - } - #endregion - - #region IXmlSerializable - public void WriteXml (XmlWriter writer) - { - throw new NotImplementedException (); - } - - public void ReadXml (XmlReader reader) - { - throw new NotImplementedException (); - } - - public XmlSchema GetSchema () - { - throw new NotImplementedException (); - } - #endregion - - internal bool DeleteNode (XomNode node) - { - Removal2 rem = new Removal2 (); - if (node.NodeType == XPathNodeType.Attribute) { - XomAttribute attr = node as XomAttribute; - rem.OwnerNode = attr.Parent; - rem.RemovedNode = node; - ((XomElement) attr.Parent).RemoveAttribute (attr); - return false; - } else { - rem.OwnerNode = node.Parent; - rem.NextSibling = node.NextSibling; - rem.RemovedNode = node; - node.Parent.RemoveChild (node); - return rem.NextSibling != null; - } - } - - internal XmlWriter CreateInsertionWriter (XomNode owner, XomNode previousSibling) - { - return new XPathDocument2InsertionWriter (owner, previousSibling, this); - } - - internal XmlWriter CreateAttributesWriter (XomNode owner) - { - return new XPathDocument2AttributeWriter (owner, this); - } - - internal void AttributeUpdate2 (XomElement element, XomAttribute oldAttr, XomAttribute newAttr) - { - AttributeUpdate2 au = new AttributeUpdate2 (); - au.Element = element; - au.OldAttribute = oldAttr; - au.NewAttribute = newAttr; - changes.Add (au); - } - - internal void AppendChild (XomParentNode parent, XomNode child) - { - Insertion2 ins = new Insertion2 (); - ins.ParentNode = parent; - ins.InsertedNode = child; - changes.Add (ins); - } - } - - public class XPathDocument2InsertionWriter : XmlWriter - { - XomNode current; - XomNode previousSibling; - XPathDocument2Editable document; - Stack nodeStack = new Stack (); - - public XPathDocument2InsertionWriter (XomNode owner, XomNode previousSibling, XPathDocument2Editable doc) - { - this.current = (XomNode) owner; - if (current == null) - throw new InvalidOperationException (); - this.previousSibling = previousSibling; - this.document = doc; - state = WriteState.Content; - } - - WriteState state; - XomAttribute attribute; - - public override WriteState WriteState { - get { return state; } - } - - public override void Close () - { - } - - public override void Flush () - { - } - - public override string LookupPrefix (string ns) - { - return current.LookupPrefix (ns); - } - - public override void WriteStartAttribute (string prefix, string name, string ns) - { - if (state != WriteState.Content) - throw new InvalidOperationException ("Current state is not inside element. Cannot start attribute."); - attribute = new XomAttribute (prefix, name, ns, String.Empty); - state = WriteState.Attribute; - } - - public override void WriteProcessingInstruction (string name, string value) - { - XomParentNode p = current as XomParentNode; - if (p == null) - throw new InvalidOperationException ("Current writer node cannot have a child."); - XomPI pi = new XomPI (name, value); - p.AppendChild (pi); - document.AppendChild (p, pi); - } - - public override void WriteComment (string text) - { - XomParentNode p = current as XomParentNode; - if (p == null) - throw new InvalidOperationException ("Current writer node cannot have a child."); - XomComment comment = new XomComment (text); - p.AppendChild (comment); - document.AppendChild (p, comment); - } - - public override void WriteCData (string text) - { - if (attribute != null) - throw new InvalidOperationException ("Current writer node is attribute. It cannot accept CDATA section."); - /* - XomParentNode p = current as XomParentNode; - if (p == null) - throw new InvalidOperationException ("Current writer node cannot have a child."); - XomText cdata = new XomText (text); - p.AppendChild (cdata); - document.AppendChild (p, cdata); - */ - WriteString (text); - } - - public override void WriteStartElement (string prefix, string name, string ns) - { - XomParentNode p = current as XomParentNode; - if (p == null) - throw new InvalidOperationException ("Current writer node cannot have a child."); - XomElement el = new XomElement (prefix, name, ns); - p.AppendChild (el); - document.AppendChild (p, el); - nodeStack.Push (current); - current = el; - } - - public override void WriteEndElement () - { - WriteFullEndElement (); - XomElement el = current as XomElement; - if (el != null && el.ChildCount == 0) - el.SetIsEmpty (true); - } - - public override void WriteFullEndElement () - { - if (nodeStack.Count == 0) - throw new InvalidOperationException ("No element is opened."); - current = nodeStack.Pop () as XomNode; - } - - public override void WriteDocType (string name, string pubid, string systemId, string intsubset) - { - throw new NotSupportedException (); - } - - public override void WriteStartDocument () - { - throw new NotSupportedException (); - } - - public override void WriteStartDocument (bool standalone) - { - throw new NotSupportedException (); - } - - public override void WriteEndDocument () - { - throw new NotSupportedException (); - } - - public override void WriteBase64 (byte [] data, int start, int length) - { - WriteString (Convert.ToBase64String (data, start, length)); - } - - public override void WriteRaw (char [] raw, int start, int length) - { - throw new NotSupportedException (); - } - - public override void WriteRaw (string raw) - { - throw new NotSupportedException (); - } - - public override void WriteSurrogateCharEntity (char msb, char lsb) - { - throw new NotSupportedException (); - } - - public override void WriteCharEntity (char c) - { - throw new NotSupportedException (); - } - - public override void WriteEntityRef (string entname) - { - throw new NotSupportedException (); - } - - public override void WriteChars (char [] data, int start, int length) - { - WriteString (new string (data, start, length)); - } - - public override void WriteString (string text) - { - if (attribute != null) - attribute.Value += text; - else { - XomParentNode p = current as XomParentNode; - if (p == null) - throw new InvalidOperationException ("Current writer node cannot have a child."); - - XomText xt = new XomText (text); - p.AppendChild (xt); - document.AppendChild (p, xt); - } - } - - public override void WriteWhitespace (string text) - { - if (attribute != null) - attribute.Value += text; - else { - XomParentNode p = current as XomParentNode; - if (p == null) - throw new InvalidOperationException ("Current writer node cannot have a child."); - - XomWhitespace ws = new XomWhitespace (text); - p.AppendChild (ws); - document.AppendChild (p, ws); - } - } - - public override void WriteEndAttribute () - { - XomElement element = current as XomElement; - if (state != WriteState.Attribute || element == null) - throw new InvalidOperationException ("Current state is not inside attribute. Cannot close attribute."); - XomAttribute old = element.GetAttribute (attribute.LocalName, attribute.Namespace); - element.AppendAttribute (attribute); - document.AttributeUpdate2 (element, old, attribute); - attribute = null; - state = WriteState.Content; - } - } - - public class XPathDocument2AttributeWriter : XmlWriter - { - XomElement element; - XPathDocument2Editable document; - - public XPathDocument2AttributeWriter (XomNode owner, XPathDocument2Editable doc) - { - element = owner as XomElement; - if (element == null) - throw new ArgumentException ("To write attributes, current node must be an element."); - state = WriteState.Content; - document = doc; - } - - WriteState state; - XomAttribute attribute; - - public override WriteState WriteState { - get { return state; } - } - - public override void Close () - { - } - - public override void Flush () - { - } - - public override string LookupPrefix (string ns) - { - return element.LookupPrefix (ns); - } - - public override void WriteStartAttribute (string prefix, string name, string ns) - { - if (state != WriteState.Content) - throw new InvalidOperationException ("Current state is not inside element. Cannot start attribute."); - attribute = new XomAttribute (prefix, name, ns, String.Empty); - state = WriteState.Attribute; - } - - public override void WriteProcessingInstruction (string name, string value) - { - throw new NotSupportedException (); - } - - public override void WriteComment (string text) - { - throw new NotSupportedException (); - } - - public override void WriteCData (string text) - { - throw new NotSupportedException (); - } - - public override void WriteStartElement (string prefix, string name, string ns) - { - throw new NotSupportedException (); - } - - public override void WriteEndElement () - { - throw new NotSupportedException (); - } - - public override void WriteFullEndElement () - { - throw new NotSupportedException (); - } - - public override void WriteDocType (string name, string pubid, string systemId, string intsubset) - { - throw new NotSupportedException (); - } - - public override void WriteStartDocument () - { - throw new NotSupportedException (); - } - - public override void WriteStartDocument (bool standalone) - { - throw new NotSupportedException (); - } - - public override void WriteEndDocument () - { - throw new NotSupportedException (); - } - - public override void WriteBase64 (byte [] data, int start, int length) - { - throw new NotSupportedException (); - } - - public override void WriteRaw (char [] raw, int start, int length) - { - throw new NotSupportedException (); - } - - public override void WriteRaw (string raw) - { - throw new NotSupportedException (); - } - - public override void WriteSurrogateCharEntity (char msb, char lsb) - { - throw new NotSupportedException (); - } - - public override void WriteCharEntity (char c) - { - throw new NotSupportedException (); - } - - public override void WriteEntityRef (string entname) - { - throw new NotSupportedException (); - } - - public override void WriteChars (char [] data, int start, int length) - { - WriteString (new string (data, start, length)); - } - - public override void WriteString (string text) - { - if (state != WriteState.Attribute) - throw new InvalidOperationException ("Current state is not inside attribute. Cannot write attribute value."); - attribute.Value += text; - } - - public override void WriteWhitespace (string text) - { - if (state != WriteState.Attribute) - throw new InvalidOperationException ("Current state is not inside attribute. Cannot write attribute value."); - else - attribute.Value += text; - } - - public override void WriteEndAttribute () - { - if (state != WriteState.Attribute) - throw new InvalidOperationException ("Current state is not inside attribute. Cannot close attribute."); - XomAttribute old = element.GetAttribute (attribute.LocalName, attribute.Namespace); - element.AppendAttribute (attribute); - document.AttributeUpdate2 (element, old, attribute); - attribute = null; - state = WriteState.Content; - } - } - - public class Insertion2 - { - // AppendChild : last child / true - // InsertBefore : current node / false - // InsertAfter : current node / true - // PrependChild : first child / false - public XomParentNode ParentNode; - public XomNode InsertedNode; - public bool Afterward; - } - - public class Removal2 - { - public XomParentNode OwnerNode; - public XomNode NextSibling; - public XomNode RemovedNode; - } - - public class AttributeUpdate2 - { - public XomElement Element; - public XomAttribute NewAttribute; - public XomAttribute OldAttribute; - } - - public class XomEditableNavigator : XPathEditableNavigator, IHasXomNode - { - XPathDocument2Editable document; - XPathNavigator navigator; - - public XomEditableNavigator (XPathDocument2Editable doc) - { - document = doc; - navigator = doc.CreateNavigator (); - } - - public XomEditableNavigator (XomEditableNavigator nav) - { - document = nav.document; - navigator = nav.navigator.Clone (); - } - - public override string BaseURI { - get { return navigator.BaseURI; } - } - - public override bool IsEmptyElement { - get { return navigator.IsEmptyElement; } - } - - public override string LocalName { - get { return navigator.LocalName; } - } - - public override XmlNameTable NameTable { - get { return navigator.NameTable; } - } - - public override string Name { - get { return navigator.Name; } - } - - public override string NamespaceURI { - get { return navigator.NamespaceURI; } - } - - public override XPathNodeType NodeType { - get { return navigator.NodeType; } - } - - public override string Prefix { - get { return navigator.Prefix; } - } - - public override string Value { - get { return navigator.Value; } - } - - public override XPathNavigator Clone () - { - return new XomEditableNavigator (this); - } - - public override XPathNavigator CreateNavigator () - { - return navigator.Clone (); - } - - public XomNode GetNode () - { - return ((IHasXomNode) navigator).GetNode (); - } - - public override bool IsSamePosition (XPathNavigator other) - { - XomEditableNavigator nav = other as XomEditableNavigator; - if (nav != null) - return navigator.IsSamePosition (nav.navigator); - else - return navigator.IsSamePosition (nav); - } - - public override bool MoveTo (XPathNavigator other) - { - XomEditableNavigator nav = other as XomEditableNavigator; - if (nav != null) - return navigator.MoveTo (nav.navigator); - else - return navigator.MoveTo (nav); - } - - public override bool MoveToFirstAttribute () - { - return navigator.MoveToFirstAttribute (); - } - - public override bool MoveToFirstChild () - { - return navigator.MoveToFirstChild (); - } - - public override bool MoveToFirstNamespace (XPathNamespaceScope scope) - { - return navigator.MoveToFirstNamespace (scope); - } - - public override bool MoveToId (string id) - { - return navigator.MoveToId (id); - } - - public override bool MoveToNext () - { - return navigator.MoveToNext (); - } - - public override bool MoveToNextAttribute () - { - return navigator.MoveToNextAttribute (); - } - - public override bool MoveToNextNamespace (XPathNamespaceScope scope) - { - return navigator.MoveToNextNamespace (scope); - } - - public override bool MoveToParent () - { - return navigator.MoveToParent (); - } - - public override bool MoveToPrevious () - { - return navigator.MoveToPrevious (); - } - - public override void Validate (XmlSchemaSet schemas, ValidationEventHandler handler) - { - throw new NotImplementedException (); -/* - // FIXME: use handler - XmlReaderSettings settings = new XmlReaderSettings (); - settings.Schemas.Add (schemas); - settings.NameTable = this.NameTable; - settings.XsdValidate = true; - settings.DtdValidate = false; - XmlReader xvr = XmlReader.Create (new XPathNavigatorReader (this), settings); - while (!xvr.EOF) - xvr.Read (); -*/ - } - - public override XmlWriter AppendChild () - { - XomNode n = ((IHasXomNode) navigator).GetNode (); - if (n == null) - throw new InvalidOperationException ("Should not happen."); - return document.CreateInsertionWriter (n, null); - } - - public override XmlWriter InsertBefore () - { - XomNode n = ((IHasXomNode) navigator).GetNode (); - return document.CreateInsertionWriter (n.Parent, n.PreviousSibling); - } - - public override XmlWriter CreateAttributes () - { - XomNode n = ((IHasXomNode) navigator).GetNode (); - return document.CreateAttributesWriter (n); - } - - public override bool DeleteCurrent () - { - XomNode n = ((IHasXomNode) navigator).GetNode (); - if (!navigator.MoveToNext ()) - navigator.MoveToParent (); - return document.DeleteNode (n); - } - - public override void SetValue (object value) - { - XomNode n = ((IHasXomNode) navigator).GetNode (); - int count = n.ChildCount; - while (n.FirstChild != null) - document.DeleteNode (n.FirstChild); - XmlWriter w = document.CreateInsertionWriter (n, null); - w.WriteValue (value); - w.Close (); - } - } -} - -#endif diff --git a/mcs/class/System.XML/Mono.Xml.XPath/XPathDocument2Navigator.cs b/mcs/class/System.XML/Mono.Xml.XPath/XPathDocument2Navigator.cs deleted file mode 100644 index 7692968d0ca..00000000000 --- a/mcs/class/System.XML/Mono.Xml.XPath/XPathDocument2Navigator.cs +++ /dev/null @@ -1,429 +0,0 @@ -//
-// Mono.Xml.XPath.XPathDocument2Navigator.cs
-//
-// Author:
-// Atsushi Enomoto <atsushi@ximian.com>
-//
-// (C)2004 Novell Inc.
-//
-// read-only XPathNavigator for editable XPathDocument.
-//
-
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-#if NET_2_0
-using System;
-using System.Collections;
-using System.Collections.Specialized;
-using System.IO;
-using System.Text;
-using System.Xml;
-using System.Xml.XPath;
-
-namespace Mono.Xml.XPath
-{
- public class XomNavigator : XPathNavigator, IHasXomNode
- {
- XomRoot root;
- XomNode current;
- XomNamespace currentNS;
-
- public XomNavigator (XomRoot root)
- {
- this.root = root;
- current = root;
- }
-
- public override string BaseURI {
- get { return current.BaseURI; }
- }
-
- public override bool IsEmptyElement {
- get { return currentNS == null && current.IsEmptyElement; }
- }
-
- public override bool HasChildren {
- get { return currentNS == null && current.ChildCount != 0; }
- }
-
- public override bool HasAttributes {
- get {
- if (currentNS != null || current.NodeType != XPathNodeType.Element)
- return false;
- XomElement el = current as XomElement;
- return el.AttributeCount != 0;
- }
- }
-
- XomNode IHasXomNode.GetNode ()
- {
- return currentNS != null ? currentNS : current;
- }
-
- public override string GetAttribute (string name, string ns)
- {
- if (currentNS != null || current.NodeType != XPathNodeType.Element)
- return String.Empty;
- XomElement el = current as XomElement;
- XomAttribute attr = el.GetAttribute (name, ns);
- return attr != null ? attr.Value : String.Empty;
- }
-
- public override XmlNameTable NameTable {
- get { return current.Root.NameTable; }
- }
-
- public override string LocalName {
- get { return current.LocalName; }
- }
-
- public override string Name {
- get { return current.PrefixedName; }
- }
-
- public override string NamespaceURI {
- get { return current.Namespace; }
- }
-
- public override string Prefix {
- get { return current.Prefix; }
- }
-
- public override string Value {
- get {
- switch (NodeType) {
- case XPathNodeType.Attribute:
- case XPathNodeType.Comment:
- case XPathNodeType.ProcessingInstruction:
- return current.Value;
- case XPathNodeType.Text:
- case XPathNodeType.Whitespace:
- case XPathNodeType.SignificantWhitespace:
- string value = current.Value;
- for (XomNode n = current.NextSibling; n != null; n = n.NextSibling) {
- switch (n.NodeType) {
- case XPathNodeType.Text:
- case XPathNodeType.Whitespace:
- case XPathNodeType.SignificantWhitespace:
- value += n.Value;
- continue;
- }
- break;
- }
- return value;
- case XPathNodeType.Element:
- case XPathNodeType.Root:
- return current.Value;
- case XPathNodeType.Namespace:
- return currentNS.Value;
- }
- return String.Empty;
- }
- }
-
- public override string XmlLang {
- get { return current.XmlLang; }
- }
-
- public override XPathNodeType NodeType {
- get { return current.NodeType; }
- }
-
- public override XPathNavigator Clone ()
- {
- XomNavigator n = new XomNavigator (root);
- n.current = current;
- n.currentNS = currentNS;
- return n;
- }
-
- public override void MoveToRoot ()
- {
- current = root;
- currentNS = null;
- }
-
- public override bool MoveToParent ()
- {
- if (currentNS != null) {
- currentNS = null;
- return true;
- }
- XomParentNode parent = current.Parent;
- if (parent == null)
- return false;
- current = parent;
- return true;
- }
-
- public override bool MoveToFirstChild ()
- {
- if (currentNS != null || current.NodeType == XPathNodeType.Attribute || current.ChildCount == 0)
- return false;
- current = current.FirstChild;
- return true;
- }
-
- public override bool MoveToFirst ()
- {
- if (currentNS != null || current.NodeType == XPathNodeType.Attribute)
- return false;
- XomParentNode pn = current.Parent;
- if (pn == null)
- return false;
- XomNode n = pn.FirstChild;
- if (n == current)
- return false;
- current = n;
- return true;
- }
-
- public override bool MoveToFirstAttribute ()
- {
- if (currentNS != null)
- return false;
- XomElement el = current as XomElement;
- if (el == null)
- return false;
- if (el.AttributeCount == 0)
- return false;
- current = el.GetAttribute (0);
- return true;
- }
-
- public override bool MoveToNextAttribute ()
- {
- XomAttribute attr = current as XomAttribute;
- if (attr == null)
- return false;
- XomElement owner = attr.Parent as XomElement;
- if (owner == null)
- return false;
- XomAttribute next = owner.GetNextAttribute (attr);
- if (next == null)
- return false;
- current = next;
- return true;
- }
-
- public override bool MoveToAttribute (string name, string ns)
- {
- if (currentNS != null || current.NodeType != XPathNodeType.Element)
- return false;
- XomElement el = current as XomElement;
- XomAttribute attr = el.GetAttribute (name, ns);
- if (attr == null)
- return false;
- current = attr;
- return true;
- }
-
- public override string GetNamespace (string prefix)
- {
- if (currentNS != null)
- return String.Empty;
- XomNamespace n = GetXomNamespace (prefix);
- if (n == null)
- return String.Empty;
- else
- return n.Namespace;
- }
-
- private XomNamespace GetXomNamespace (string prefix)
- {
- if (current.NodeType != XPathNodeType.Element)
- return null;
- if (prefix == "xml")
- return XomNamespace.Xml;
- XomElement el = current as XomElement;
- do {
- XomNamespace n = el.GetLocalNamespace (prefix);
- if (n != null)
- return n;
- el = el.Parent as XomElement;
- } while (el != null);
- return null;
- }
-
- public override bool MoveToNamespace (string prefix)
- {
- if (currentNS != null)
- return false;
- XomNamespace n = GetXomNamespace (prefix);
- if (n == null)
- return false;
- currentNS = n;
- return true;
- }
-
- public override bool MoveToFirstNamespace (XPathNamespaceScope scope)
- {
- if (currentNS != null || current.NodeType != XPathNodeType.Element)
- return false;
- XomElement el = current as XomElement;
- XomNamespace n = null;
- switch (scope) {
- case XPathNamespaceScope.Local:
- if (el.NamespaceCount > 0)
- n = el.GetLocalNamespace (0);
- break;
- default:
- do {
- if (el.NamespaceCount > 0) {
- n = el.GetLocalNamespace (0);
- break;
- }
- el = el.Parent as XomElement;
- } while (el != null);
- break;
- }
- if (n != null) {
- currentNS = n;
- return true;
- }
- else if (scope == XPathNamespaceScope.All) {
- currentNS = XomNamespace.Xml;
- return true;
- }
- return false;
- }
-
- public override bool MoveToNextNamespace (XPathNamespaceScope scope)
- {
- if (currentNS == null || currentNS == XomNamespace.Xml)
- return false;
- XomElement el = currentNS.Parent as XomElement;
- XomNamespace n = el.GetNextLocalNamespace (currentNS);
- if (n != null) {
- currentNS = n;
- return true;
- }
- switch (scope) {
- case XPathNamespaceScope.Local:
- return false;
- default:
- el = el.Parent as XomElement;
- while (el != null) {
- if (el.NamespaceCount > 0) {
- n = el.GetLocalNamespace (0);
- break;
- }
- el = el.Parent as XomElement;
- }
- break;
- }
- if (n != null) {
- currentNS = n;
- return true;
- }
- else if (scope == XPathNamespaceScope.All) {
- currentNS = XomNamespace.Xml;
- return true;
- }
- return false;
- }
-
- public override bool MoveToNext ()
- {
- if (currentNS != null)
- return false;
- switch (NodeType) {
- case XPathNodeType.Text:
- case XPathNodeType.SignificantWhitespace:
- case XPathNodeType.Whitespace:
- for (XomNode t = current.NextSibling; t != null; t = t.NextSibling) {
- switch (t.NodeType) {
- case XPathNodeType.Text:
- case XPathNodeType.SignificantWhitespace:
- case XPathNodeType.Whitespace:
- continue;
- }
- current = t;
- return true;
- }
- return false;
- default:
- XomNode n = current.NextSibling;
- if (n == null)
- return false;
- current = n;
- return true;
- }
- }
-
- public override bool MoveToPrevious ()
- {
- if (currentNS != null)
- return false;
- XomNode n = current.PreviousSibling;
- if (n == null)
- return false;
- current = n;
-
- switch (NodeType) {
- case XPathNodeType.Text:
- case XPathNodeType.SignificantWhitespace:
- case XPathNodeType.Whitespace:
- for (XomNode t = current.PreviousSibling; t != null; t = t.NextSibling) {
- switch (t.NodeType) {
- case XPathNodeType.Text:
- case XPathNodeType.SignificantWhitespace:
- case XPathNodeType.Whitespace:
- current = t;
- continue;
- }
- break;
- }
- break;
- }
-
- return true;
- }
-
- public override bool IsSamePosition (XPathNavigator other)
- {
- XomNavigator xom = other as XomNavigator;
- if (xom == null || root != xom.root)
- return false;
- return current == xom.current && currentNS == xom.currentNS;
- }
-
- public override bool MoveTo (XPathNavigator other)
- {
- XomNavigator xom = other as XomNavigator;
- if (xom == null)
- return false;
- current = xom.current;
- currentNS = xom.currentNS;
- return true;
- }
-
- public override bool MoveToId (string id)
- {
- XomElement el = root.GetIdenticalNode (id);
- if (el == null)
- return false;
- current = el;
- return true;
- }
- }
-}
-#endif
|