();
- _done = false;
- }
-
- public override int Count
- {
- get
- {
- if (!_done)
- {
- ReadUntil(Int32.MaxValue);
- }
- return _list.Count;
- }
- }
-
- private static readonly object[] s_nullparams = { };
-
- private XmlNode GetNode(XPathNavigator n)
- {
- IHasXmlNode iHasNode = (IHasXmlNode)n;
- return iHasNode.GetNode();
- }
-
- internal int ReadUntil(int index)
- {
- int count = _list.Count;
- while (!_done && count <= index)
- {
- if (_nodeIterator.MoveNext())
- {
- XmlNode n = GetNode(_nodeIterator.Current);
- if (n != null)
- {
- _list.Add(n);
- count++;
- }
- }
- else
- {
- _done = true;
- break;
- }
- }
- return count;
- }
-
- public override XmlNode Item(int index)
- {
- if (_list.Count <= index)
- {
- ReadUntil(index);
- }
- if (index < 0 || _list.Count <= index)
- {
- return null;
- }
- return _list[index];
- }
-
- public override IEnumerator GetEnumerator()
- {
- return new XmlNodeListEnumerator(this);
- }
- }
-
- internal class XmlNodeListEnumerator : IEnumerator
- {
- private XPathNodeList _list;
- private int _index;
- private bool _valid;
-
- public XmlNodeListEnumerator(XPathNodeList list)
- {
- _list = list;
- _index = -1;
- _valid = false;
- }
-
- public void Reset()
- {
- _index = -1;
- }
-
- public bool MoveNext()
- {
- _index++;
- int count = _list.ReadUntil(_index + 1); // read past for delete-node case
- if (count - 1 < _index)
- {
- return false;
- }
- _valid = (_list[_index] != null);
- return _valid;
- }
-
- public object Current
- {
- get
- {
- if (_valid)
- {
- return _list[_index];
- }
- return null;
- }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlAttribute.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlAttribute.cs
deleted file mode 100644
index d8c2ebfc09b..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlAttribute.cs
+++ /dev/null
@@ -1,421 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
- using Microsoft.Xml.Schema;
- using Microsoft.Xml.XPath;
- using System.Diagnostics;
-
- // Represents an attribute of the XMLElement object. Valid and default
- // values for the attribute are defined in a DTD or schema.
- public class XmlAttribute : XmlNode
- {
- private XmlName _name;
- private XmlLinkedNode _lastChild;
-
- internal XmlAttribute(XmlName name, XmlDocument doc) : base(doc)
- {
- Debug.Assert(name != null);
- Debug.Assert(doc != null);
- this.parentNode = null;
- if (!doc.IsLoading)
- {
- XmlDocument.CheckName(name.Prefix);
- XmlDocument.CheckName(name.LocalName);
- }
- if (name.LocalName.Length == 0)
- throw new ArgumentException(ResXml.Xdom_Attr_Name);
- _name = name;
- }
-
- internal int LocalNameHash
- {
- get { return _name.HashCode; }
- }
-
- protected internal XmlAttribute(string prefix, string localName, string namespaceURI, XmlDocument doc)
- : this(doc.AddAttrXmlName(prefix, localName, namespaceURI, null), doc)
- {
- }
-
- internal XmlName XmlName
- {
- get { return _name; }
- set { _name = value; }
- }
-
- // Creates a duplicate of this node.
- public override XmlNode CloneNode(bool deep)
- {
- // CloneNode for attributes is deep irrespective of parameter 'deep' value
- Debug.Assert(OwnerDocument != null);
- XmlDocument doc = OwnerDocument;
- XmlAttribute attr = doc.CreateAttribute(Prefix, LocalName, NamespaceURI);
- attr.CopyChildren(doc, this, true);
- return attr;
- }
-
- // Gets the parent of this node (for nodes that can have parents).
- public override XmlNode ParentNode
- {
- get { return null; }
- }
-
- // Gets the name of the node.
- public override String Name
- {
- get { return _name.Name; }
- }
-
- // Gets the name of the node without the namespace prefix.
- public override String LocalName
- {
- get { return _name.LocalName; }
- }
-
- // Gets the namespace URI of this node.
- public override String NamespaceURI
- {
- get { return _name.NamespaceURI; }
- }
-
- // Gets or sets the namespace prefix of this node.
- public override String Prefix
- {
- get { return _name.Prefix; }
- set { _name = _name.OwnerDocument.AddAttrXmlName(value, LocalName, NamespaceURI, SchemaInfo); }
- }
-
- // Gets the type of the current node.
- public override XmlNodeType NodeType
- {
- get { return XmlNodeType.Attribute; }
- }
-
- // Gets the XmlDocument that contains this node.
- public override XmlDocument OwnerDocument
- {
- get
- {
- return _name.OwnerDocument;
- }
- }
-
- // Gets or sets the value of the node.
- public override String Value
- {
- get { return InnerText; }
- set { InnerText = value; } //use InnerText which has perf optimization
- }
-
- public override IXmlSchemaInfo SchemaInfo
- {
- get
- {
- return _name;
- }
- }
-
- public override String InnerText
- {
- set
- {
- if (PrepareOwnerElementInElementIdAttrMap())
- {
- string innerText = base.InnerText;
- base.InnerText = value;
- ResetOwnerElementInElementIdAttrMap(innerText);
- }
- else
- {
- base.InnerText = value;
- }
- }
- }
-
- internal bool PrepareOwnerElementInElementIdAttrMap()
- {
- XmlDocument ownerDocument = OwnerDocument;
- if (ownerDocument.DtdSchemaInfo != null)
- { // DTD exists
- XmlElement ownerElement = OwnerElement;
- if (ownerElement != null)
- {
- return ownerElement.Attributes.PrepareParentInElementIdAttrMap(Prefix, LocalName);
- }
- }
- return false;
- }
-
- internal void ResetOwnerElementInElementIdAttrMap(string oldInnerText)
- {
- XmlElement ownerElement = OwnerElement;
- if (ownerElement != null)
- {
- ownerElement.Attributes.ResetParentInElementIdAttrMap(oldInnerText, InnerText);
- }
- }
-
- internal override bool IsContainer
- {
- get { return true; }
- }
-
- //the function is provided only at Load time to speed up Load process
- internal override XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
- {
- XmlNodeChangedEventArgs args = doc.GetInsertEventArgsForLoad(newChild, this);
-
- if (args != null)
- doc.BeforeEvent(args);
-
- XmlLinkedNode newNode = (XmlLinkedNode)newChild;
-
- if (_lastChild == null)
- { // if LastNode == null
- newNode.next = newNode;
- _lastChild = newNode;
- newNode.SetParentForLoad(this);
- }
- else
- {
- XmlLinkedNode refNode = _lastChild; // refNode = LastNode;
- newNode.next = refNode.next;
- refNode.next = newNode;
- _lastChild = newNode; // LastNode = newNode;
- if (refNode.IsText
- && newNode.IsText)
- {
- NestTextNodes(refNode, newNode);
- }
- else
- {
- newNode.SetParentForLoad(this);
- }
- }
-
- if (args != null)
- doc.AfterEvent(args);
-
- return newNode;
- }
-
- internal override XmlLinkedNode LastNode
- {
- get { return _lastChild; }
- set { _lastChild = value; }
- }
-
- internal override bool IsValidChildType(XmlNodeType type)
- {
- return (type == XmlNodeType.Text) || (type == XmlNodeType.EntityReference);
- }
-
- // Gets a value indicating whether the value was explicitly set.
- public virtual bool Specified
- {
- get { return true; }
- }
-
- public override XmlNode InsertBefore(XmlNode newChild, XmlNode refChild)
- {
- XmlNode node;
- if (PrepareOwnerElementInElementIdAttrMap())
- {
- string innerText = InnerText;
- node = base.InsertBefore(newChild, refChild);
- ResetOwnerElementInElementIdAttrMap(innerText);
- }
- else
- {
- node = base.InsertBefore(newChild, refChild);
- }
- return node;
- }
-
- public override XmlNode InsertAfter(XmlNode newChild, XmlNode refChild)
- {
- XmlNode node;
- if (PrepareOwnerElementInElementIdAttrMap())
- {
- string innerText = InnerText;
- node = base.InsertAfter(newChild, refChild);
- ResetOwnerElementInElementIdAttrMap(innerText);
- }
- else
- {
- node = base.InsertAfter(newChild, refChild);
- }
- return node;
- }
-
- public override XmlNode ReplaceChild(XmlNode newChild, XmlNode oldChild)
- {
- XmlNode node;
- if (PrepareOwnerElementInElementIdAttrMap())
- {
- string innerText = InnerText;
- node = base.ReplaceChild(newChild, oldChild);
- ResetOwnerElementInElementIdAttrMap(innerText);
- }
- else
- {
- node = base.ReplaceChild(newChild, oldChild);
- }
- return node;
- }
-
- public override XmlNode RemoveChild(XmlNode oldChild)
- {
- XmlNode node;
- if (PrepareOwnerElementInElementIdAttrMap())
- {
- string innerText = InnerText;
- node = base.RemoveChild(oldChild);
- ResetOwnerElementInElementIdAttrMap(innerText);
- }
- else
- {
- node = base.RemoveChild(oldChild);
- }
- return node;
- }
-
- public override XmlNode PrependChild(XmlNode newChild)
- {
- XmlNode node;
- if (PrepareOwnerElementInElementIdAttrMap())
- {
- string innerText = InnerText;
- node = base.PrependChild(newChild);
- ResetOwnerElementInElementIdAttrMap(innerText);
- }
- else
- {
- node = base.PrependChild(newChild);
- }
- return node;
- }
-
- public override XmlNode AppendChild(XmlNode newChild)
- {
- XmlNode node;
- if (PrepareOwnerElementInElementIdAttrMap())
- {
- string innerText = InnerText;
- node = base.AppendChild(newChild);
- ResetOwnerElementInElementIdAttrMap(innerText);
- }
- else
- {
- node = base.AppendChild(newChild);
- }
- return node;
- }
-
- // DOM Level 2
-
- // Gets the XmlElement node that contains this attribute.
- public virtual XmlElement OwnerElement
- {
- get
- {
- return parentNode as XmlElement;
- }
- }
-
- // Gets or sets the markup representing just the children of this node.
- public override string InnerXml
- {
- set
- {
- RemoveAll();
- XmlLoader loader = new XmlLoader();
- loader.LoadInnerXmlAttribute(this, value);
- }
- }
-
- // Saves the node to the specified XmlWriter.
- public override void WriteTo(XmlWriter w)
- {
- w.WriteStartAttribute(Prefix, LocalName, NamespaceURI);
- WriteContentTo(w);
- w.WriteEndAttribute();
- }
-
- // Saves all the children of the node to the specified XmlWriter.
- public override void WriteContentTo(XmlWriter w)
- {
- for (XmlNode node = FirstChild; node != null; node = node.NextSibling)
- {
- node.WriteTo(w);
- }
- }
-
- public override String BaseURI
- {
- get
- {
- if (OwnerElement != null)
- return OwnerElement.BaseURI;
- return String.Empty;
- }
- }
-
- internal override void SetParent(XmlNode node)
- {
- this.parentNode = node;
- }
-
- internal override XmlSpace XmlSpace
- {
- get
- {
- if (OwnerElement != null)
- return OwnerElement.XmlSpace;
- return XmlSpace.None;
- }
- }
-
- internal override String XmlLang
- {
- get
- {
- if (OwnerElement != null)
- return OwnerElement.XmlLang;
- return String.Empty;
- }
- }
- internal override XPathNodeType XPNodeType
- {
- get
- {
- if (IsNamespace)
- {
- return XPathNodeType.Namespace;
- }
- return XPathNodeType.Attribute;
- }
- }
-
- internal override string XPLocalName
- {
- get
- {
- if (_name.Prefix.Length == 0 && _name.LocalName == "xmlns") return string.Empty;
- return _name.LocalName;
- }
- }
-
- internal bool IsNamespace
- {
- get
- {
- return Ref.Equal(_name.NamespaceURI, _name.OwnerDocument.strReservedXmlns);
- }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlAttributeCollection.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlAttributeCollection.cs
deleted file mode 100644
index 999f0ec8e4f..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlAttributeCollection.cs
+++ /dev/null
@@ -1,416 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-
-namespace Microsoft.Xml
-{
- using System;
- using System.Collections;
- using System.Diagnostics;
-
- // Represents a collection of attributes that can be accessed by name or index.
- public sealed class XmlAttributeCollection : XmlNamedNodeMap, ICollection
- {
- internal XmlAttributeCollection(XmlNode parent) : base(parent)
- {
- }
-
- // Gets the attribute with the specified index.
- [System.Runtime.CompilerServices.IndexerName("ItemOf")]
- public XmlAttribute this[int i]
- {
- get
- {
- try
- {
- return (XmlAttribute)nodes[i];
- }
- catch (ArgumentOutOfRangeException)
- {
- throw new IndexOutOfRangeException(ResXml.Xdom_IndexOutOfRange);
- }
- }
- }
-
- // Gets the attribute with the specified name.
- [System.Runtime.CompilerServices.IndexerName("ItemOf")]
- public XmlAttribute this[string name]
- {
- get
- {
- int hash = XmlName.GetHashCode(name);
-
- for (int i = 0; i < nodes.Count; i++)
- {
- XmlAttribute node = (XmlAttribute)nodes[i];
-
- if (hash == node.LocalNameHash
- && name == node.Name)
- {
- return node;
- }
- }
-
- return null;
- }
- }
-
- // Gets the attribute with the specified LocalName and NamespaceUri.
- [System.Runtime.CompilerServices.IndexerName("ItemOf")]
- public XmlAttribute this[string localName, string namespaceURI]
- {
- get
- {
- int hash = XmlName.GetHashCode(localName);
-
- for (int i = 0; i < nodes.Count; i++)
- {
- XmlAttribute node = (XmlAttribute)nodes[i];
-
- if (hash == node.LocalNameHash
- && localName == node.LocalName
- && namespaceURI == node.NamespaceURI)
- {
- return node;
- }
- }
-
- return null;
- }
- }
-
- internal int FindNodeOffset(XmlAttribute node)
- {
- for (int i = 0; i < nodes.Count; i++)
- {
- XmlAttribute tmp = (XmlAttribute)nodes[i];
-
- if (tmp.LocalNameHash == node.LocalNameHash
- && tmp.Name == node.Name
- && tmp.NamespaceURI == node.NamespaceURI)
- {
- return i;
- }
- }
- return -1;
- }
-
- internal int FindNodeOffsetNS(XmlAttribute node)
- {
- for (int i = 0; i < nodes.Count; i++)
- {
- XmlAttribute tmp = (XmlAttribute)nodes[i];
- if (tmp.LocalNameHash == node.LocalNameHash
- && tmp.LocalName == node.LocalName
- && tmp.NamespaceURI == node.NamespaceURI)
- {
- return i;
- }
- }
- return -1;
- }
-
- // Adds a XmlNode using its Name property
- public override XmlNode SetNamedItem(XmlNode node)
- {
- if (node != null && !(node is XmlAttribute))
- throw new ArgumentException(ResXml.Xdom_AttrCol_Object);
-
- int offset = FindNodeOffset(node.LocalName, node.NamespaceURI);
- if (offset == -1)
- {
- return InternalAppendAttribute((XmlAttribute)node);
- }
- else
- {
- XmlNode oldNode = base.RemoveNodeAt(offset);
- InsertNodeAt(offset, node);
- return oldNode;
- }
- }
-
- // Inserts the specified node as the first node in the collection.
- public XmlAttribute Prepend(XmlAttribute node)
- {
- if (node.OwnerDocument != null && node.OwnerDocument != parent.OwnerDocument)
- throw new ArgumentException(ResXml.Xdom_NamedNode_Context);
-
- if (node.OwnerElement != null)
- Detach(node);
-
- RemoveDuplicateAttribute(node);
-
- InsertNodeAt(0, node);
- return node;
- }
-
- // Inserts the specified node as the last node in the collection.
- public XmlAttribute Append(XmlAttribute node)
- {
- XmlDocument doc = node.OwnerDocument;
- if (doc == null || doc.IsLoading == false)
- {
- if (doc != null && doc != parent.OwnerDocument)
- {
- throw new ArgumentException(ResXml.Xdom_NamedNode_Context);
- }
- if (node.OwnerElement != null)
- {
- Detach(node);
- }
- AddNode(node);
- }
- else
- {
- base.AddNodeForLoad(node, doc);
- InsertParentIntoElementIdAttrMap(node);
- }
- return node;
- }
-
- // Inserts the specified attribute immediately before the specified reference attribute.
- public XmlAttribute InsertBefore(XmlAttribute newNode, XmlAttribute refNode)
- {
- if (newNode == refNode)
- return newNode;
-
- if (refNode == null)
- return Append(newNode);
-
- if (refNode.OwnerElement != parent)
- throw new ArgumentException(ResXml.Xdom_AttrCol_Insert);
-
- if (newNode.OwnerDocument != null && newNode.OwnerDocument != parent.OwnerDocument)
- throw new ArgumentException(ResXml.Xdom_NamedNode_Context);
-
- if (newNode.OwnerElement != null)
- Detach(newNode);
-
- int offset = FindNodeOffset(refNode.LocalName, refNode.NamespaceURI);
- Debug.Assert(offset != -1); // the if statement above guarantees that the ref node is in the collection
-
- int dupoff = RemoveDuplicateAttribute(newNode);
- if (dupoff >= 0 && dupoff < offset)
- offset--;
- InsertNodeAt(offset, newNode);
-
- return newNode;
- }
-
- // Inserts the specified attribute immediately after the specified reference attribute.
- public XmlAttribute InsertAfter(XmlAttribute newNode, XmlAttribute refNode)
- {
- if (newNode == refNode)
- return newNode;
-
- if (refNode == null)
- return Prepend(newNode);
-
- if (refNode.OwnerElement != parent)
- throw new ArgumentException(ResXml.Xdom_AttrCol_Insert);
-
- if (newNode.OwnerDocument != null && newNode.OwnerDocument != parent.OwnerDocument)
- throw new ArgumentException(ResXml.Xdom_NamedNode_Context);
-
- if (newNode.OwnerElement != null)
- Detach(newNode);
-
- int offset = FindNodeOffset(refNode.LocalName, refNode.NamespaceURI);
- Debug.Assert(offset != -1); // the if statement above guarantees that the ref node is in the collection
-
- int dupoff = RemoveDuplicateAttribute(newNode);
- if (dupoff >= 0 && dupoff < offset)
- offset--;
- InsertNodeAt(offset + 1, newNode);
-
- return newNode;
- }
-
- // Removes the specified attribute node from the map.
- public XmlAttribute Remove(XmlAttribute node)
- {
- int cNodes = nodes.Count;
- for (int offset = 0; offset < cNodes; offset++)
- {
- if (nodes[offset] == node)
- {
- RemoveNodeAt(offset);
- return node;
- }
- }
- return null;
- }
-
- // Removes the attribute node with the specified index from the map.
- public XmlAttribute RemoveAt(int i)
- {
- if (i < 0 || i >= Count)
- return null;
-
- return (XmlAttribute)RemoveNodeAt(i);
- }
-
- // Removes all attributes from the map.
- public void RemoveAll()
- {
- int n = Count;
- while (n > 0)
- {
- n--;
- RemoveAt(n);
- }
- }
-
- void ICollection.CopyTo(Array array, int index)
- {
- for (int i = 0, max = Count; i < max; i++, index++)
- array.SetValue(nodes[i], index);
- }
-
- bool ICollection.IsSynchronized
- {
- get { return false; }
- }
-
- object ICollection.SyncRoot
- {
- get { return this; }
- }
-
- int ICollection.Count
- {
- get { return base.Count; }
- }
-
- public void CopyTo(XmlAttribute[] array, int index)
- {
- for (int i = 0, max = Count; i < max; i++, index++)
- array[index] = (XmlAttribute)(((XmlNode)nodes[i]).CloneNode(true));
- }
-
- internal override XmlNode AddNode(XmlNode node)
- {
- //should be sure by now that the node doesn't have the same name with an existing node in the collection
- RemoveDuplicateAttribute((XmlAttribute)node);
- XmlNode retNode = base.AddNode(node);
- Debug.Assert(retNode is XmlAttribute);
- InsertParentIntoElementIdAttrMap((XmlAttribute)node);
- return retNode;
- }
-
- internal override XmlNode InsertNodeAt(int i, XmlNode node)
- {
- XmlNode retNode = base.InsertNodeAt(i, node);
- InsertParentIntoElementIdAttrMap((XmlAttribute)node);
- return retNode;
- }
-
- internal override XmlNode RemoveNodeAt(int i)
- {
- //remove the node without checking replacement
- XmlNode retNode = base.RemoveNodeAt(i);
- Debug.Assert(retNode is XmlAttribute);
- RemoveParentFromElementIdAttrMap((XmlAttribute)retNode);
- // after remove the attribute, we need to check if a default attribute node should be created and inserted into the tree
- XmlAttribute defattr = parent.OwnerDocument.GetDefaultAttribute((XmlElement)parent, retNode.Prefix, retNode.LocalName, retNode.NamespaceURI);
- if (defattr != null)
- InsertNodeAt(i, defattr);
- return retNode;
- }
-
- internal void Detach(XmlAttribute attr)
- {
- attr.OwnerElement.Attributes.Remove(attr);
- }
-
- //insert the parent element node into the map
- internal void InsertParentIntoElementIdAttrMap(XmlAttribute attr)
- {
- XmlElement parentElem = parent as XmlElement;
- if (parentElem != null)
- {
- if (parent.OwnerDocument == null)
- return;
- XmlName attrname = parent.OwnerDocument.GetIDInfoByElement(parentElem.XmlName);
- if (attrname != null && attrname.Prefix == attr.XmlName.Prefix && attrname.LocalName == attr.XmlName.LocalName)
- {
- parent.OwnerDocument.AddElementWithId(attr.Value, parentElem); //add the element into the hashtable
- }
- }
- }
-
- //remove the parent element node from the map when the ID attribute is removed
- internal void RemoveParentFromElementIdAttrMap(XmlAttribute attr)
- {
- XmlElement parentElem = parent as XmlElement;
- if (parentElem != null)
- {
- if (parent.OwnerDocument == null)
- return;
- XmlName attrname = parent.OwnerDocument.GetIDInfoByElement(parentElem.XmlName);
- if (attrname != null && attrname.Prefix == attr.XmlName.Prefix && attrname.LocalName == attr.XmlName.LocalName)
- {
- parent.OwnerDocument.RemoveElementWithId(attr.Value, parentElem); //remove the element from the hashtable
- }
- }
- }
-
- //the function checks if there is already node with the same name existing in the collection
- // if so, remove it because the new one will be inserted to replace this one (could be in different position though )
- // by the calling function later
- internal int RemoveDuplicateAttribute(XmlAttribute attr)
- {
- int ind = FindNodeOffset(attr.LocalName, attr.NamespaceURI);
- if (ind != -1)
- {
- XmlAttribute at = (XmlAttribute)nodes[ind];
- base.RemoveNodeAt(ind);
- RemoveParentFromElementIdAttrMap(at);
- }
- return ind;
- }
-
- internal bool PrepareParentInElementIdAttrMap(string attrPrefix, string attrLocalName)
- {
- XmlElement parentElem = parent as XmlElement;
- Debug.Assert(parentElem != null);
- XmlDocument doc = parent.OwnerDocument;
- Debug.Assert(doc != null);
- //The returned attrname if not null is the name with namespaceURI being set to string.Empty
- //Because DTD doesn't support namespaceURI so all comparisons are based on no namespaceURI (string.Empty);
- XmlName attrname = doc.GetIDInfoByElement(parentElem.XmlName);
- if (attrname != null && attrname.Prefix == attrPrefix && attrname.LocalName == attrLocalName)
- {
- return true;
- }
- return false;
- }
-
- internal void ResetParentInElementIdAttrMap(string oldVal, string newVal)
- {
- XmlElement parentElem = parent as XmlElement;
- Debug.Assert(parentElem != null);
- XmlDocument doc = parent.OwnerDocument;
- Debug.Assert(doc != null);
- doc.RemoveElementWithId(oldVal, parentElem); //add the element into the hashtable
- doc.AddElementWithId(newVal, parentElem);
- }
-
- // WARNING:
- // For performance reasons, this function does not check
- // for xml attributes within the collection with the same full name.
- // This means that any caller of this function must be sure that
- // a duplicate attribute does not exist.
- internal XmlAttribute InternalAppendAttribute(XmlAttribute node)
- {
- // a duplicate node better not exist
- Debug.Assert(-1 == FindNodeOffset(node));
-
- XmlNode retNode = base.AddNode(node);
- Debug.Assert(retNode is XmlAttribute);
- InsertParentIntoElementIdAttrMap((XmlAttribute)node);
- return (XmlAttribute)retNode;
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlCDATASection.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlCDATASection.cs
deleted file mode 100644
index 07473c3f184..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlCDATASection.cs
+++ /dev/null
@@ -1,118 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
- using System.Text;
- using System.Diagnostics;
- using Microsoft.Xml.XPath;
-
- // Used to quote or escape blocks of text to keep that text from being
- // interpreted as markup language.
- public class XmlCDataSection : XmlCharacterData
- {
- protected internal XmlCDataSection(string data, XmlDocument doc) : base(data, doc)
- {
- }
-
- // Gets the name of the node.
- public override String Name
- {
- get
- {
- return OwnerDocument.strCDataSectionName;
- }
- }
-
- // Gets the name of the node without the namespace prefix.
- public override String LocalName
- {
- get
- {
- return OwnerDocument.strCDataSectionName;
- }
- }
-
- // Gets the type of the current node.
- public override XmlNodeType NodeType
- {
- get
- {
- return XmlNodeType.CDATA;
- }
- }
-
- public override XmlNode ParentNode
- {
- get
- {
- switch (parentNode.NodeType)
- {
- case XmlNodeType.Document:
- return null;
- case XmlNodeType.Text:
- case XmlNodeType.CDATA:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- XmlNode parent = parentNode.parentNode;
- while (parent.IsText)
- {
- parent = parent.parentNode;
- }
- return parent;
- default:
- return parentNode;
- }
- }
- }
-
- // Creates a duplicate of this node.
- public override XmlNode CloneNode(bool deep)
- {
- Debug.Assert(OwnerDocument != null);
- return OwnerDocument.CreateCDataSection(Data);
- }
-
- // Saves the node to the specified XmlWriter.
- public override void WriteTo(XmlWriter w)
- {
- w.WriteCData(Data);
- }
-
- // Saves the node to the specified XmlWriter.
- public override void WriteContentTo(XmlWriter w)
- {
- // Intentionally do nothing
- }
-
- internal override XPathNodeType XPNodeType
- {
- get
- {
- return XPathNodeType.Text;
- }
- }
-
- internal override bool IsText
- {
- get
- {
- return true;
- }
- }
-
- public override XmlNode PreviousText
- {
- get
- {
- if (parentNode.IsText)
- {
- return parentNode;
- }
- return null;
- }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlCharacterData.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlCharacterData.cs
deleted file mode 100644
index 7b4ef05d2a7..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlCharacterData.cs
+++ /dev/null
@@ -1,231 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- using System.Diagnostics;
- using System.Text;
- using Microsoft.Xml.XPath;
-
- // Provides text-manipulation methods that are used by several classes.
- public abstract class XmlCharacterData : XmlLinkedNode
- {
- private string _data;
-
- //base(doc) will throw exception if doc is null.
- protected internal XmlCharacterData(string data, XmlDocument doc) : base(doc)
- {
- _data = data;
- }
-
- // Gets or sets the value of the node.
- public override String Value
- {
- get { return Data; }
- set { Data = value; }
- }
-
- // Gets or sets the concatenated values of the node and
- // all its children.
- public override string InnerText
- {
- get { return Value; }
- set { Value = value; }
- }
-
- // Contains this node's data.
- public virtual string Data
- {
- get
- {
- if (_data != null)
- {
- return _data;
- }
- else
- {
- return String.Empty;
- }
- }
-
- set
- {
- XmlNode parent = ParentNode;
- XmlNodeChangedEventArgs args = GetEventArgs(this, parent, parent, _data, value, XmlNodeChangedAction.Change);
-
- if (args != null)
- BeforeEvent(args);
-
- _data = value;
-
- if (args != null)
- AfterEvent(args);
- }
- }
-
- // Gets the length of the data, in characters.
- public virtual int Length
- {
- get
- {
- if (_data != null)
- {
- return _data.Length;
- }
- return 0;
- }
- }
-
- // Retrieves a substring of the full string from the specified range.
- public virtual String Substring(int offset, int count)
- {
- int len = _data != null ? _data.Length : 0;
- if (len > 0)
- {
- if (len < (offset + count))
- {
- count = len - offset;
- }
- return _data.Substring(offset, count);
- }
- return String.Empty;
- }
-
- // Appends the specified string to the end of the character
- // data of the node.
- public virtual void AppendData(String strData)
- {
- XmlNode parent = ParentNode;
- int capacity = _data != null ? _data.Length : 0;
- if (strData != null) capacity += strData.Length;
- string newValue = new StringBuilder(capacity).Append(_data).Append(strData).ToString();
- XmlNodeChangedEventArgs args = GetEventArgs(this, parent, parent, _data, newValue, XmlNodeChangedAction.Change);
-
- if (args != null)
- BeforeEvent(args);
-
- _data = newValue;
-
- if (args != null)
- AfterEvent(args);
- }
-
- // Insert the specified string at the specified character offset.
- public virtual void InsertData(int offset, string strData)
- {
- XmlNode parent = ParentNode;
- int capacity = _data != null ? _data.Length : 0;
- if (strData != null) capacity += strData.Length;
- string newValue = new StringBuilder(capacity).Append(_data).Insert(offset, strData).ToString();
- XmlNodeChangedEventArgs args = GetEventArgs(this, parent, parent, _data, newValue, XmlNodeChangedAction.Change);
- if (args != null)
- BeforeEvent(args);
-
- _data = newValue;
-
- if (args != null)
- AfterEvent(args);
- }
-
- // Remove a range of characters from the node.
- public virtual void DeleteData(int offset, int count)
- {
- //Debug.Assert(offset >= 0 && offset <= Length);
-
- int len = _data != null ? _data.Length : 0;
- if (len > 0)
- {
- if (len < (offset + count))
- {
- count = Math.Max(len - offset, 0);
- }
- }
-
- string newValue = new StringBuilder(_data).Remove(offset, count).ToString();
- XmlNode parent = ParentNode;
- XmlNodeChangedEventArgs args = GetEventArgs(this, parent, parent, _data, newValue, XmlNodeChangedAction.Change);
-
- if (args != null)
- BeforeEvent(args);
-
- _data = newValue;
-
- if (args != null)
- AfterEvent(args);
- }
-
- // Replace the specified number of characters starting at the specified offset with the
- // specified string.
- public virtual void ReplaceData(int offset, int count, String strData)
- {
- //Debug.Assert(offset >= 0 && offset <= Length);
-
- int len = _data != null ? _data.Length : 0;
- if (len > 0)
- {
- if (len < (offset + count))
- {
- count = Math.Max(len - offset, 0);
- }
- }
-
- StringBuilder temp = new StringBuilder(_data).Remove(offset, count);
- string newValue = temp.Insert(offset, strData).ToString();
-
- XmlNode parent = ParentNode;
- XmlNodeChangedEventArgs args = GetEventArgs(this, parent, parent, _data, newValue, XmlNodeChangedAction.Change);
-
- if (args != null)
- BeforeEvent(args);
-
- _data = newValue;
-
- if (args != null)
- AfterEvent(args);
- }
-
- internal bool CheckOnData(string data)
- {
- return XmlCharType.Instance.IsOnlyWhitespace(data);
- }
-
- internal bool DecideXPNodeTypeForTextNodes(XmlNode node, ref XPathNodeType xnt)
- {
- //returns true - if all siblings of the node are processed else returns false.
- //The reference XPathNodeType argument being passed in is the watermark that
- //changes according to the siblings nodetype and will contain the correct
- //nodetype when it returns.
-
- Debug.Assert(XmlDocument.IsTextNode(node.NodeType) || (node.ParentNode != null && node.ParentNode.NodeType == XmlNodeType.EntityReference));
- while (node != null)
- {
- switch (node.NodeType)
- {
- case XmlNodeType.Whitespace:
- break;
- case XmlNodeType.SignificantWhitespace:
- xnt = XPathNodeType.SignificantWhitespace;
- break;
- case XmlNodeType.Text:
- case XmlNodeType.CDATA:
- xnt = XPathNodeType.Text;
- return false;
- case XmlNodeType.EntityReference:
- if (!DecideXPNodeTypeForTextNodes(node.FirstChild, ref xnt))
- {
- return false;
- }
- break;
- default:
- return false;
- }
- node = node.NextSibling;
- }
- return true;
- }
- }
-}
-
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlChildEnumerator.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlChildEnumerator.cs
deleted file mode 100644
index 693ee8ef76f..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlChildEnumerator.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- using System.Collections;
-
- internal sealed class XmlChildEnumerator : IEnumerator
- {
- internal XmlNode container;
- internal XmlNode child;
- internal bool isFirst;
-
- internal XmlChildEnumerator(XmlNode container)
- {
- this.container = container;
- this.child = container.FirstChild;
- this.isFirst = true;
- }
-
- bool IEnumerator.MoveNext()
- {
- return this.MoveNext();
- }
-
- internal bool MoveNext()
- {
- if (isFirst)
- {
- child = container.FirstChild;
- isFirst = false;
- }
- else if (child != null)
- {
- child = child.NextSibling;
- }
-
- return child != null;
- }
-
- void IEnumerator.Reset()
- {
- isFirst = true;
- child = container.FirstChild;
- }
-
- object IEnumerator.Current
- {
- get
- {
- return this.Current;
- }
- }
-
- internal XmlNode Current
- {
- get
- {
- if (isFirst || child == null)
- throw new InvalidOperationException(ResXml.Xml_InvalidOperation);
-
- return child;
- }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlChildNodes.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlChildNodes.cs
deleted file mode 100644
index 3fb2ba6a4fc..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlChildNodes.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- using System.Collections;
-
- internal class XmlChildNodes : XmlNodeList
- {
- private XmlNode _container;
-
- public XmlChildNodes(XmlNode container)
- {
- _container = container;
- }
-
- public override XmlNode Item(int i)
- {
- // Out of range indexes return a null XmlNode
- if (i < 0)
- return null;
- for (XmlNode n = _container.FirstChild; n != null; n = n.NextSibling, i--)
- {
- if (i == 0)
- return n;
- }
- return null;
- }
-
- public override int Count
- {
- get
- {
- int c = 0;
- for (XmlNode n = _container.FirstChild; n != null; n = n.NextSibling)
- {
- c++;
- }
- return c;
- }
- }
-
- public override IEnumerator GetEnumerator()
- {
- if (_container.FirstChild == null)
- {
- return XmlDocument.EmptyEnumerator;
- }
- else
- {
- return new XmlChildEnumerator(_container);
- }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlComment.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlComment.cs
deleted file mode 100644
index 7f3024410a3..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlComment.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- using Microsoft.Xml.XPath;
- using System.Diagnostics;
-
- // Represents the content of an XML comment.
- public class XmlComment : XmlCharacterData
- {
- protected internal XmlComment(string comment, XmlDocument doc) : base(comment, doc)
- {
- }
-
- // Gets the name of the node.
- public override String Name
- {
- get { return OwnerDocument.strCommentName; }
- }
-
- // Gets the name of the current node without the namespace prefix.
- public override String LocalName
- {
- get { return OwnerDocument.strCommentName; }
- }
-
- // Gets the type of the current node.
- public override XmlNodeType NodeType
- {
- get { return XmlNodeType.Comment; }
- }
-
- // Creates a duplicate of this node.
- public override XmlNode CloneNode(bool deep)
- {
- Debug.Assert(OwnerDocument != null);
- return OwnerDocument.CreateComment(Data);
- }
-
- // Saves the node to the specified XmlWriter.
- public override void WriteTo(XmlWriter w)
- {
- w.WriteComment(Data);
- }
-
- // Saves all the children of the node to the specified XmlWriter.
- public override void WriteContentTo(XmlWriter w)
- {
- // Intentionally do nothing
- }
-
- internal override XPathNodeType XPNodeType { get { return XPathNodeType.Comment; } }
- }
-}
-
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDeclaration.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDeclaration.cs
deleted file mode 100644
index ede7fbe769f..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDeclaration.cs
+++ /dev/null
@@ -1,174 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- using System.Text;
- using System.Diagnostics;
-
- // Represents the xml declaration nodes:
- public class XmlDeclaration : XmlLinkedNode
- {
- private const string YES = "yes";
- private const string NO = "no";
-
- private string _version;
- private string _encoding;
- private string _standalone;
-
- protected internal XmlDeclaration(string version, string encoding, string standalone, XmlDocument doc) : base(doc)
- {
- if (!IsValidXmlVersion(version))
- throw new ArgumentException(ResXml.Xdom_Version);
- if ((standalone != null) && (standalone.Length > 0))
- if ((standalone != YES) && (standalone != NO))
- throw new ArgumentException(string.Format(ResXml.Xdom_standalone, standalone));
- this.Encoding = encoding;
- this.Standalone = standalone;
- this.Version = version;
- }
-
-
- // The version attribute for
- public string Version
- {
- get { return _version; }
- internal set { _version = value; }
- }
-
- // Specifies the value of the encoding attribute, as for
- //
- public string Encoding
- {
- get { return _encoding; }
- set { _encoding = ((value == null) ? String.Empty : value); }
- }
-
- // Specifies the value of the standalone attribute.
- public string Standalone
- {
- get { return _standalone; }
- set
- {
- if (value == null)
- _standalone = String.Empty;
- else if (value.Length == 0 || value == YES || value == NO)
- _standalone = value;
- else
- throw new ArgumentException(string.Format(ResXml.Xdom_standalone, value));
- }
- }
-
- public override String Value
- {
- get { return InnerText; }
- set { InnerText = value; }
- }
-
-
- // Gets or sets the concatenated values of the node and
- // all its children.
- public override string InnerText
- {
- get
- {
- StringBuilder strb = new StringBuilder("version=\"" + Version + "\"");
- if (Encoding.Length > 0)
- {
- strb.Append(" encoding=\"");
- strb.Append(Encoding);
- strb.Append("\"");
- }
- if (Standalone.Length > 0)
- {
- strb.Append(" standalone=\"");
- strb.Append(Standalone);
- strb.Append("\"");
- }
- return strb.ToString();
- }
-
- set
- {
- string tempVersion = null;
- string tempEncoding = null;
- string tempStandalone = null;
- string orgEncoding = this.Encoding;
- string orgStandalone = this.Standalone;
- string orgVersion = this.Version;
-
- XmlLoader.ParseXmlDeclarationValue(value, out tempVersion, out tempEncoding, out tempStandalone);
-
- try
- {
- if (tempVersion != null && !IsValidXmlVersion(tempVersion))
- throw new ArgumentException(ResXml.Xdom_Version);
- Version = tempVersion;
-
- if (tempEncoding != null)
- Encoding = tempEncoding;
- if (tempStandalone != null)
- Standalone = tempStandalone;
- }
- catch
- {
- Encoding = orgEncoding;
- Standalone = orgStandalone;
- Version = orgVersion;
- throw;
- }
- }
- }
-
- //override methods and properties from XmlNode
-
- // Gets the name of the node.
- public override String Name
- {
- get
- {
- return "xml";
- }
- }
-
- // Gets the name of the current node without the namespace prefix.
- public override string LocalName
- {
- get { return Name; }
- }
-
- // Gets the type of the current node.
- public override XmlNodeType NodeType
- {
- get { return XmlNodeType.XmlDeclaration; }
- }
-
- // Creates a duplicate of this node.
- public override XmlNode CloneNode(bool deep)
- {
- Debug.Assert(OwnerDocument != null);
- return OwnerDocument.CreateXmlDeclaration(Version, Encoding, Standalone);
- }
-
- // Saves the node to the specified XmlWriter.
- public override void WriteTo(XmlWriter w)
- {
- w.WriteProcessingInstruction(Name, InnerText);
- }
-
-
- // Saves all the children of the node to the specified XmlWriter.
- public override void WriteContentTo(XmlWriter w)
- {
- // Intentionally do nothing since the node doesn't have children.
- }
-
- private bool IsValidXmlVersion(string ver)
- {
- return ver.Length >= 3 && ver[0] == '1' && ver[1] == '.' && XmlCharType.IsOnlyDigits(ver, 2, ver.Length - 2);
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDocument.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDocument.cs
deleted file mode 100644
index dc6a12d3cc8..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDocument.cs
+++ /dev/null
@@ -1,1780 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
- using System.Collections;
- using System.Diagnostics;
- using System.IO;
- using System.Text;
- using Microsoft.Xml.Schema;
- using Microsoft.Xml.XPath;
- using System.Security;
- // using System.Security.Permissions;
- using System.Globalization;
- using System.Runtime.Versioning;
-
- // Represents an entire document. An XmlDocument contains XML data.
- public class XmlDocument : XmlNode
- {
- private XmlImplementation _implementation;
- private DomNameTable _domNameTable; // hash table of XmlName
- private XmlLinkedNode _lastChild;
- private XmlNamedNodeMap _entities;
- private Hashtable _htElementIdMap;
- private Hashtable _htElementIDAttrDecl; //key: id; object: the ArrayList of the elements that have the same id (connected or disconnected)
- private SchemaInfo _schemaInfo;
- private XmlSchemaSet _schemas; // schemas associated with the cache
- private bool _reportValidity;
- //This variable represents the actual loading status. Since, IsLoading will
- //be manipulated soemtimes for adding content to EntityReference this variable
- //has been added which would always represent the loading status of document.
- private bool _actualLoadingStatus;
-
- private XmlNodeChangedEventHandler _onNodeInsertingDelegate;
- private XmlNodeChangedEventHandler _onNodeInsertedDelegate;
- private XmlNodeChangedEventHandler _onNodeRemovingDelegate;
- private XmlNodeChangedEventHandler _onNodeRemovedDelegate;
- private XmlNodeChangedEventHandler _onNodeChangingDelegate;
- private XmlNodeChangedEventHandler _onNodeChangedDelegate;
-
- // false if there are no ent-ref present, true if ent-ref nodes are or were present (i.e. if all ent-ref were removed, the doc will not clear this flag)
- internal bool fEntRefNodesPresent;
- internal bool fCDataNodesPresent;
-
- private bool _preserveWhitespace;
- private bool _isLoading;
-
- // special name strings for
- internal string strDocumentName;
- internal string strDocumentFragmentName;
- internal string strCommentName;
- internal string strTextName;
- internal string strCDataSectionName;
- internal string strEntityName;
- internal string strID;
- internal string strXmlns;
- internal string strXml;
- internal string strSpace;
- internal string strLang;
- internal string strEmpty;
-
- internal string strNonSignificantWhitespaceName;
- internal string strSignificantWhitespaceName;
- internal string strReservedXmlns;
- internal string strReservedXml;
-
- internal String baseURI;
-
- private XmlResolver _resolver;
- internal bool bSetResolver;
- internal object objLock;
-
- private XmlAttribute _namespaceXml;
-
- static internal EmptyEnumerator EmptyEnumerator = new EmptyEnumerator();
- static internal IXmlSchemaInfo NotKnownSchemaInfo = new XmlSchemaInfo(XmlSchemaValidity.NotKnown);
- static internal IXmlSchemaInfo ValidSchemaInfo = new XmlSchemaInfo(XmlSchemaValidity.Valid);
- static internal IXmlSchemaInfo InvalidSchemaInfo = new XmlSchemaInfo(XmlSchemaValidity.Invalid);
-
- // Initializes a new instance of the XmlDocument class.
- public XmlDocument() : this(new XmlImplementation())
- {
- }
-
- // Initializes a new instance
- // of the XmlDocument class with the specified XmlNameTable.
- public XmlDocument(XmlNameTable nt) : this(new XmlImplementation(nt))
- {
- }
-
- protected internal XmlDocument(XmlImplementation imp) : base()
- {
- _implementation = imp;
- _domNameTable = new DomNameTable(this);
-
- // force the following string instances to be default in the nametable
- XmlNameTable nt = this.NameTable;
- nt.Add(string.Empty);
- strDocumentName = nt.Add("#document");
- strDocumentFragmentName = nt.Add("#document-fragment");
- strCommentName = nt.Add("#comment");
- strTextName = nt.Add("#text");
- strCDataSectionName = nt.Add("#cdata-section");
- strEntityName = nt.Add("#entity");
- strID = nt.Add("id");
- strNonSignificantWhitespaceName = nt.Add("#whitespace");
- strSignificantWhitespaceName = nt.Add("#significant-whitespace");
- strXmlns = nt.Add("xmlns");
- strXml = nt.Add("xml");
- strSpace = nt.Add("space");
- strLang = nt.Add("lang");
- strReservedXmlns = nt.Add(XmlReservedNs.NsXmlNs);
- strReservedXml = nt.Add(XmlReservedNs.NsXml);
- strEmpty = nt.Add(String.Empty);
- baseURI = String.Empty;
-
- objLock = new object();
- }
-
- internal SchemaInfo DtdSchemaInfo
- {
- get { return _schemaInfo; }
- set { _schemaInfo = value; }
- }
-
- // NOTE: This does not correctly check start name char, but we cannot change it since it would be a breaking change.
- internal static void CheckName(String name)
- {
- int endPos = ValidateNames.ParseNmtoken(name, 0);
- if (endPos < name.Length)
- {
- throw new XmlException(ResXml.Xml_BadNameChar, XmlException.BuildCharExceptionArgs(name, endPos));
- }
- }
-
- internal XmlName AddXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo)
- {
- XmlName n = _domNameTable.AddName(prefix, localName, namespaceURI, schemaInfo);
- Debug.Assert((prefix == null) ? (n.Prefix.Length == 0) : (prefix == n.Prefix));
- Debug.Assert(n.LocalName == localName);
- Debug.Assert((namespaceURI == null) ? (n.NamespaceURI.Length == 0) : (n.NamespaceURI == namespaceURI));
- return n;
- }
-
- internal XmlName GetXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo)
- {
- XmlName n = _domNameTable.GetName(prefix, localName, namespaceURI, schemaInfo);
- Debug.Assert(n == null || ((prefix == null) ? (n.Prefix.Length == 0) : (prefix == n.Prefix)));
- Debug.Assert(n == null || n.LocalName == localName);
- Debug.Assert(n == null || ((namespaceURI == null) ? (n.NamespaceURI.Length == 0) : (n.NamespaceURI == namespaceURI)));
- return n;
- }
-
- internal XmlName AddAttrXmlName(string prefix, string localName, string namespaceURI, IXmlSchemaInfo schemaInfo)
- {
- XmlName xmlName = AddXmlName(prefix, localName, namespaceURI, schemaInfo);
- Debug.Assert((prefix == null) ? (xmlName.Prefix.Length == 0) : (prefix == xmlName.Prefix));
- Debug.Assert(xmlName.LocalName == localName);
- Debug.Assert((namespaceURI == null) ? (xmlName.NamespaceURI.Length == 0) : (xmlName.NamespaceURI == namespaceURI));
-
- if (!this.IsLoading)
- {
- // Use atomized versions instead of prefix, localName and nsURI
- object oPrefix = xmlName.Prefix;
- object oNamespaceURI = xmlName.NamespaceURI;
- object oLocalName = xmlName.LocalName;
- if ((oPrefix == (object)strXmlns || (oPrefix == (object)strEmpty && oLocalName == (object)strXmlns)) ^ (oNamespaceURI == (object)strReservedXmlns))
- throw new ArgumentException(string.Format(ResXml.Xdom_Attr_Reserved_XmlNS, namespaceURI));
- }
- return xmlName;
- }
-
- internal bool AddIdInfo(XmlName eleName, XmlName attrName)
- {
- //when XmlLoader call XmlDocument.AddInfo, the element.XmlName and attr.XmlName
- //have already been replaced with the ones that don't have namespace values (or just
- //string.Empty) because in DTD, the namespace is not supported
- if (_htElementIDAttrDecl == null || _htElementIDAttrDecl[eleName] == null)
- {
- if (_htElementIDAttrDecl == null)
- _htElementIDAttrDecl = new Hashtable();
- _htElementIDAttrDecl.Add(eleName, attrName);
- return true;
- }
- return false;
- }
-
- private XmlName GetIDInfoByElement_(XmlName eleName)
- {
- //When XmlDocument is getting the IDAttribute for a given element,
- //we need only compare the prefix and localname of element.XmlName with
- //the registered htElementIDAttrDecl.
- XmlName newName = GetXmlName(eleName.Prefix, eleName.LocalName, string.Empty, null);
- if (newName != null)
- {
- return (XmlName)(_htElementIDAttrDecl[newName]);
- }
- return null;
- }
-
- internal XmlName GetIDInfoByElement(XmlName eleName)
- {
- if (_htElementIDAttrDecl == null)
- return null;
- else
- return GetIDInfoByElement_(eleName);
- }
-
- private WeakReference GetElement(ArrayList elementList, XmlElement elem)
- {
- ArrayList gcElemRefs = new ArrayList();
- foreach (WeakReference elemRef in elementList)
- {
- if (!elemRef.IsAlive)
- //take notes on the garbage collected nodes
- gcElemRefs.Add(elemRef);
- else
- {
- if ((XmlElement)(elemRef.Target) == elem)
- return elemRef;
- }
- }
- //Clear out the gced elements
- foreach (WeakReference elemRef in gcElemRefs)
- elementList.Remove(elemRef);
- return null;
- }
-
- internal void AddElementWithId(string id, XmlElement elem)
- {
- if (_htElementIdMap == null || !_htElementIdMap.Contains(id))
- {
- if (_htElementIdMap == null)
- _htElementIdMap = new Hashtable();
- ArrayList elementList = new ArrayList();
- elementList.Add(new WeakReference(elem));
- _htElementIdMap.Add(id, elementList);
- }
- else
- {
- // there are other element(s) that has the same id
- ArrayList elementList = (ArrayList)(_htElementIdMap[id]);
- if (GetElement(elementList, elem) == null)
- elementList.Add(new WeakReference(elem));
- }
- }
-
- internal void RemoveElementWithId(string id, XmlElement elem)
- {
- if (_htElementIdMap != null && _htElementIdMap.Contains(id))
- {
- ArrayList elementList = (ArrayList)(_htElementIdMap[id]);
- WeakReference elemRef = GetElement(elementList, elem);
- if (elemRef != null)
- {
- elementList.Remove(elemRef);
- if (elementList.Count == 0)
- _htElementIdMap.Remove(id);
- }
- }
- }
-
-
- // Creates a duplicate of this node.
- public override XmlNode CloneNode(bool deep)
- {
- XmlDocument clone = Implementation.CreateDocument();
- clone.SetBaseURI(this.baseURI);
- if (deep)
- clone.ImportChildren(this, clone, deep);
-
- return clone;
- }
-
- // Gets the type of the current node.
- public override XmlNodeType NodeType
- {
- get { return XmlNodeType.Document; }
- }
-
- public override XmlNode ParentNode
- {
- get { return null; }
- }
-
- // Gets the node for the DOCTYPE declaration.
- public virtual XmlDocumentType DocumentType
- {
- get { return (XmlDocumentType)FindChild(XmlNodeType.DocumentType); }
- }
-
- internal virtual XmlDeclaration Declaration
- {
- get
- {
- if (HasChildNodes)
- {
- XmlDeclaration dec = FirstChild as XmlDeclaration;
- return dec;
- }
- return null;
- }
- }
-
- // Gets the XmlImplementation object for this document.
- public XmlImplementation Implementation
- {
- get { return _implementation; }
- }
-
- // Gets the name of the node.
- public override String Name
- {
- get { return strDocumentName; }
- }
-
- // Gets the name of the current node without the namespace prefix.
- public override String LocalName
- {
- get { return strDocumentName; }
- }
-
- // Gets the root XmlElement for the document.
- public XmlElement DocumentElement
- {
- get { return (XmlElement)FindChild(XmlNodeType.Element); }
- }
-
- internal override bool IsContainer
- {
- get { return true; }
- }
-
- internal override XmlLinkedNode LastNode
- {
- get { return _lastChild; }
- set { _lastChild = value; }
- }
-
- // Gets the XmlDocument that contains this node.
- public override XmlDocument OwnerDocument
- {
- get { return null; }
- }
-
- public XmlSchemaSet Schemas
- {
- get
- {
- if (_schemas == null)
- {
- _schemas = new XmlSchemaSet(NameTable);
- }
- return _schemas;
- }
-
- set
- {
- _schemas = value;
- }
- }
-
- internal bool CanReportValidity
- {
- get { return _reportValidity; }
- }
-
- internal bool HasSetResolver
- {
- get { return bSetResolver; }
- }
-
- internal XmlResolver GetResolver()
- {
- return _resolver;
- }
-
- public virtual XmlResolver XmlResolver
- {
- set
- {
- _resolver = value;
- if (!bSetResolver)
- bSetResolver = true;
-
- XmlDocumentType dtd = this.DocumentType;
- if (dtd != null)
- {
- dtd.DtdSchemaInfo = null;
- }
- }
- }
- internal override bool IsValidChildType(XmlNodeType type)
- {
- switch (type)
- {
- case XmlNodeType.ProcessingInstruction:
- case XmlNodeType.Comment:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- return true;
-
- case XmlNodeType.DocumentType:
- if (DocumentType != null)
- throw new InvalidOperationException(ResXml.Xdom_DualDocumentTypeNode);
- return true;
-
- case XmlNodeType.Element:
- if (DocumentElement != null)
- throw new InvalidOperationException(ResXml.Xdom_DualDocumentElementNode);
- return true;
-
- case XmlNodeType.XmlDeclaration:
- if (Declaration != null)
- throw new InvalidOperationException(ResXml.Xdom_DualDeclarationNode);
- return true;
-
- default:
- return false;
- }
- }
- // the function examines all the siblings before the refNode
- // if any of the nodes has type equals to "nt", return true; otherwise, return false;
- private bool HasNodeTypeInPrevSiblings(XmlNodeType nt, XmlNode refNode)
- {
- if (refNode == null)
- return false;
-
- XmlNode node = null;
- if (refNode.ParentNode != null)
- node = refNode.ParentNode.FirstChild;
- while (node != null)
- {
- if (node.NodeType == nt)
- return true;
- if (node == refNode)
- break;
- node = node.NextSibling;
- }
- return false;
- }
-
- // the function examines all the siblings after the refNode
- // if any of the nodes has the type equals to "nt", return true; otherwise, return false;
- private bool HasNodeTypeInNextSiblings(XmlNodeType nt, XmlNode refNode)
- {
- XmlNode node = refNode;
- while (node != null)
- {
- if (node.NodeType == nt)
- return true;
- node = node.NextSibling;
- }
- return false;
- }
-
- internal override bool CanInsertBefore(XmlNode newChild, XmlNode refChild)
- {
- if (refChild == null)
- refChild = FirstChild;
-
- if (refChild == null)
- return true;
-
- switch (newChild.NodeType)
- {
- case XmlNodeType.XmlDeclaration:
- return (refChild == FirstChild);
-
- case XmlNodeType.ProcessingInstruction:
- case XmlNodeType.Comment:
- return refChild.NodeType != XmlNodeType.XmlDeclaration;
-
- case XmlNodeType.DocumentType:
- {
- if (refChild.NodeType != XmlNodeType.XmlDeclaration)
- {
- //if refChild is not the XmlDeclaration node, only need to go through the sibling before and including refChild to
- // make sure no Element ( rootElem node ) before the current position
- return !HasNodeTypeInPrevSiblings(XmlNodeType.Element, refChild.PreviousSibling);
- }
- }
- break;
-
- case XmlNodeType.Element:
- {
- if (refChild.NodeType != XmlNodeType.XmlDeclaration)
- {
- //if refChild is not the XmlDeclaration node, only need to go through the siblings after and including the refChild to
- // make sure no DocType node and XmlDeclaration node after the current posistion.
- return !HasNodeTypeInNextSiblings(XmlNodeType.DocumentType, refChild);
- }
- }
- break;
- }
-
- return false;
- }
-
- internal override bool CanInsertAfter(XmlNode newChild, XmlNode refChild)
- {
- if (refChild == null)
- refChild = LastChild;
-
- if (refChild == null)
- return true;
-
- switch (newChild.NodeType)
- {
- case XmlNodeType.ProcessingInstruction:
- case XmlNodeType.Comment:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- return true;
-
- case XmlNodeType.DocumentType:
- {
- //we will have to go through all the siblings before the refChild just to make sure no Element node ( rootElem )
- // before the current position
- return !HasNodeTypeInPrevSiblings(XmlNodeType.Element, refChild);
- }
-
- case XmlNodeType.Element:
- {
- return !HasNodeTypeInNextSiblings(XmlNodeType.DocumentType, refChild.NextSibling);
- }
- }
-
- return false;
- }
-
- // Creates an XmlAttribute with the specified name.
- public XmlAttribute CreateAttribute(String name)
- {
- String prefix = String.Empty;
- String localName = String.Empty;
- String namespaceURI = String.Empty;
-
- SplitName(name, out prefix, out localName);
-
- SetDefaultNamespace(prefix, localName, ref namespaceURI);
-
- return CreateAttribute(prefix, localName, namespaceURI);
- }
-
- internal void SetDefaultNamespace(String prefix, String localName, ref String namespaceURI)
- {
- if (prefix == strXmlns || (prefix.Length == 0 && localName == strXmlns))
- {
- namespaceURI = strReservedXmlns;
- }
- else if (prefix == strXml)
- {
- namespaceURI = strReservedXml;
- }
- }
-
- // Creates a XmlCDataSection containing the specified data.
- public virtual XmlCDataSection CreateCDataSection(String data)
- {
- fCDataNodesPresent = true;
- return new XmlCDataSection(data, this);
- }
-
- // Creates an XmlComment containing the specified data.
- public virtual XmlComment CreateComment(String data)
- {
- return new XmlComment(data, this);
- }
-
- // Returns a new XmlDocumentType object.
- // [PermissionSetAttribute( SecurityAction.InheritanceDemand, Name = "FullTrust" )]
- public virtual XmlDocumentType CreateDocumentType(string name, string publicId, string systemId, string internalSubset)
- {
- return new XmlDocumentType(name, publicId, systemId, internalSubset, this);
- }
-
- // Creates an XmlDocumentFragment.
- public virtual XmlDocumentFragment CreateDocumentFragment()
- {
- return new XmlDocumentFragment(this);
- }
-
- // Creates an element with the specified name.
- public XmlElement CreateElement(String name)
- {
- string prefix = String.Empty;
- string localName = String.Empty;
- SplitName(name, out prefix, out localName);
- return CreateElement(prefix, localName, string.Empty);
- }
-
-
- internal void AddDefaultAttributes(XmlElement elem)
- {
- SchemaInfo schInfo = DtdSchemaInfo;
- SchemaElementDecl ed = GetSchemaElementDecl(elem);
- if (ed != null && ed.AttDefs != null)
- {
- IDictionaryEnumerator attrDefs = ed.AttDefs.GetEnumerator();
- while (attrDefs.MoveNext())
- {
- SchemaAttDef attdef = (SchemaAttDef)attrDefs.Value;
- if (attdef.Presence == SchemaDeclBase.Use.Default ||
- attdef.Presence == SchemaDeclBase.Use.Fixed)
- {
- //build a default attribute and return
- string attrPrefix = string.Empty;
- string attrLocalname = attdef.Name.Name;
- string attrNamespaceURI = string.Empty;
- if (schInfo.SchemaType == SchemaType.DTD)
- attrPrefix = attdef.Name.Namespace;
- else
- {
- attrPrefix = attdef.Prefix;
- attrNamespaceURI = attdef.Name.Namespace;
- }
- XmlAttribute defattr = PrepareDefaultAttribute(attdef, attrPrefix, attrLocalname, attrNamespaceURI);
- elem.SetAttributeNode(defattr);
- }
- }
- }
- }
-
- private SchemaElementDecl GetSchemaElementDecl(XmlElement elem)
- {
- SchemaInfo schInfo = DtdSchemaInfo;
- if (schInfo != null)
- {
- //build XmlQualifiedName used to identify the element schema declaration
- XmlQualifiedName qname = new XmlQualifiedName(elem.LocalName, schInfo.SchemaType == SchemaType.DTD ? elem.Prefix : elem.NamespaceURI);
- //get the schema info for the element
- SchemaElementDecl elemDecl;
- if (schInfo.ElementDecls.TryGetValue(qname, out elemDecl))
- {
- return elemDecl;
- }
- }
- return null;
- }
-
- //Will be used by AddDeafulatAttributes() and GetDefaultAttribute() methods
- private XmlAttribute PrepareDefaultAttribute(SchemaAttDef attdef, string attrPrefix, string attrLocalname, string attrNamespaceURI)
- {
- SetDefaultNamespace(attrPrefix, attrLocalname, ref attrNamespaceURI);
- XmlAttribute defattr = CreateDefaultAttribute(attrPrefix, attrLocalname, attrNamespaceURI);
- //parsing the default value for the default attribute
- defattr.InnerXml = attdef.DefaultValueRaw;
- //during the expansion of the tree, the flag could be set to true, we need to set it back.
- XmlUnspecifiedAttribute unspAttr = defattr as XmlUnspecifiedAttribute;
- if (unspAttr != null)
- {
- unspAttr.SetSpecified(false);
- }
- return defattr;
- }
-
- // Creates an XmlEntityReference with the specified name.
- public virtual XmlEntityReference CreateEntityReference(String name)
- {
- return new XmlEntityReference(name, this);
- }
-
- // Creates a XmlProcessingInstruction with the specified name
- // and data strings.
- public virtual XmlProcessingInstruction CreateProcessingInstruction(String target, String data)
- {
- return new XmlProcessingInstruction(target, data, this);
- }
-
- // Creates a XmlDeclaration node with the specified values.
- public virtual XmlDeclaration CreateXmlDeclaration(String version, string encoding, string standalone)
- {
- return new XmlDeclaration(version, encoding, standalone, this);
- }
-
- // Creates an XmlText with the specified text.
- public virtual XmlText CreateTextNode(String text)
- {
- return new XmlText(text, this);
- }
-
- // Creates a XmlSignificantWhitespace node.
- public virtual XmlSignificantWhitespace CreateSignificantWhitespace(string text)
- {
- return new XmlSignificantWhitespace(text, this);
- }
-
- public override XPathNavigator CreateNavigator()
- {
- return CreateNavigator(this);
- }
-
- internal protected virtual XPathNavigator CreateNavigator(XmlNode node)
- {
- XmlNodeType nodeType = node.NodeType;
- XmlNode parent;
- XmlNodeType parentType;
-
- switch (nodeType)
- {
- case XmlNodeType.EntityReference:
- case XmlNodeType.Entity:
- case XmlNodeType.DocumentType:
- case XmlNodeType.Notation:
- case XmlNodeType.XmlDeclaration:
- return null;
- case XmlNodeType.Text:
- case XmlNodeType.CDATA:
- case XmlNodeType.SignificantWhitespace:
- parent = node.ParentNode;
- if (parent != null)
- {
- do
- {
- parentType = parent.NodeType;
- if (parentType == XmlNodeType.Attribute)
- {
- return null;
- }
- else if (parentType == XmlNodeType.EntityReference)
- {
- parent = parent.ParentNode;
- }
- else
- {
- break;
- }
- }
- while (parent != null);
- }
- node = NormalizeText(node);
- break;
- case XmlNodeType.Whitespace:
- parent = node.ParentNode;
- if (parent != null)
- {
- do
- {
- parentType = parent.NodeType;
- if (parentType == XmlNodeType.Document
- || parentType == XmlNodeType.Attribute)
- {
- return null;
- }
- else if (parentType == XmlNodeType.EntityReference)
- {
- parent = parent.ParentNode;
- }
- else
- {
- break;
- }
- }
- while (parent != null);
- }
- node = NormalizeText(node);
- break;
- default:
- break;
- }
- return new DocumentXPathNavigator(this, node);
- }
-
- internal static bool IsTextNode(XmlNodeType nt)
- {
- switch (nt)
- {
- case XmlNodeType.Text:
- case XmlNodeType.CDATA:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- return true;
- default:
- return false;
- }
- }
-
- private XmlNode NormalizeText(XmlNode n)
- {
- XmlNode retnode = null;
- while (IsTextNode(n.NodeType))
- {
- retnode = n;
- n = n.PreviousSibling;
-
- if (n == null)
- {
- XmlNode intnode = retnode;
- while (true)
- {
- if (intnode.ParentNode != null && intnode.ParentNode.NodeType == XmlNodeType.EntityReference)
- {
- if (intnode.ParentNode.PreviousSibling != null)
- {
- n = intnode.ParentNode.PreviousSibling;
- break;
- }
- else
- {
- intnode = intnode.ParentNode;
- if (intnode == null)
- break;
- }
- }
- else
- break;
- }
- }
-
- if (n == null)
- break;
- while (n.NodeType == XmlNodeType.EntityReference)
- {
- n = n.LastChild;
- }
- }
- return retnode;
- }
-
- // Creates a XmlWhitespace node.
- public virtual XmlWhitespace CreateWhitespace(string text)
- {
- return new XmlWhitespace(text, this);
- }
-
- // Returns an XmlNodeList containing
- // a list of all descendant elements that match the specified name.
- public virtual XmlNodeList GetElementsByTagName(String name)
- {
- return new XmlElementList(this, name);
- }
-
- // DOM Level 2
-
- // Creates an XmlAttribute with the specified LocalName
- // and NamespaceURI.
- public XmlAttribute CreateAttribute(String qualifiedName, String namespaceURI)
- {
- string prefix = String.Empty;
- string localName = String.Empty;
-
- SplitName(qualifiedName, out prefix, out localName);
- return CreateAttribute(prefix, localName, namespaceURI);
- }
-
- // Creates an XmlElement with the specified LocalName and
- // NamespaceURI.
- public XmlElement CreateElement(String qualifiedName, String namespaceURI)
- {
- string prefix = String.Empty;
- string localName = String.Empty;
- SplitName(qualifiedName, out prefix, out localName);
- return CreateElement(prefix, localName, namespaceURI);
- }
-
- // Returns a XmlNodeList containing
- // a list of all descendant elements that match the specified name.
- public virtual XmlNodeList GetElementsByTagName(String localName, String namespaceURI)
- {
- return new XmlElementList(this, localName, namespaceURI);
- }
-
- // Returns the XmlElement with the specified ID.
- public virtual XmlElement GetElementById(string elementId)
- {
- if (_htElementIdMap != null)
- {
- ArrayList elementList = (ArrayList)(_htElementIdMap[elementId]);
- if (elementList != null)
- {
- foreach (WeakReference elemRef in elementList)
- {
- XmlElement elem = (XmlElement)elemRef.Target;
- if (elem != null
- && elem.IsConnected())
- return elem;
- }
- }
- }
- return null;
- }
-
- // Imports a node from another document to this document.
- public virtual XmlNode ImportNode(XmlNode node, bool deep)
- {
- return ImportNodeInternal(node, deep);
- }
-
- private XmlNode ImportNodeInternal(XmlNode node, bool deep)
- {
- XmlNode newNode = null;
-
- if (node == null)
- {
- throw new InvalidOperationException(ResXml.Xdom_Import_NullNode);
- }
- else
- {
- switch (node.NodeType)
- {
- case XmlNodeType.Element:
- newNode = CreateElement(node.Prefix, node.LocalName, node.NamespaceURI);
- ImportAttributes(node, newNode);
- if (deep)
- ImportChildren(node, newNode, deep);
- break;
-
- case XmlNodeType.Attribute:
- Debug.Assert(((XmlAttribute)node).Specified);
- newNode = CreateAttribute(node.Prefix, node.LocalName, node.NamespaceURI);
- ImportChildren(node, newNode, true);
- break;
-
- case XmlNodeType.Text:
- newNode = CreateTextNode(node.Value);
- break;
- case XmlNodeType.Comment:
- newNode = CreateComment(node.Value);
- break;
- case XmlNodeType.ProcessingInstruction:
- newNode = CreateProcessingInstruction(node.Name, node.Value);
- break;
- case XmlNodeType.XmlDeclaration:
- XmlDeclaration decl = (XmlDeclaration)node;
- newNode = CreateXmlDeclaration(decl.Version, decl.Encoding, decl.Standalone);
- break;
- case XmlNodeType.CDATA:
- newNode = CreateCDataSection(node.Value);
- break;
- case XmlNodeType.DocumentType:
- XmlDocumentType docType = (XmlDocumentType)node;
- newNode = CreateDocumentType(docType.Name, docType.PublicId, docType.SystemId, docType.InternalSubset);
- break;
- case XmlNodeType.DocumentFragment:
- newNode = CreateDocumentFragment();
- if (deep)
- ImportChildren(node, newNode, deep);
- break;
-
- case XmlNodeType.EntityReference:
- newNode = CreateEntityReference(node.Name);
- // we don't import the children of entity reference because they might result in different
- // children nodes given different namesapce context in the new document.
- break;
-
- case XmlNodeType.Whitespace:
- newNode = CreateWhitespace(node.Value);
- break;
-
- case XmlNodeType.SignificantWhitespace:
- newNode = CreateSignificantWhitespace(node.Value);
- break;
-
- default:
- throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, ResXml.Xdom_Import, node.NodeType.ToString()));
- }
- }
-
- return newNode;
- }
-
- private void ImportAttributes(XmlNode fromElem, XmlNode toElem)
- {
- int cAttr = fromElem.Attributes.Count;
- for (int iAttr = 0; iAttr < cAttr; iAttr++)
- {
- if (fromElem.Attributes[iAttr].Specified)
- toElem.Attributes.SetNamedItem(ImportNodeInternal(fromElem.Attributes[iAttr], true));
- }
- }
-
- private void ImportChildren(XmlNode fromNode, XmlNode toNode, bool deep)
- {
- Debug.Assert(toNode.NodeType != XmlNodeType.EntityReference);
- for (XmlNode n = fromNode.FirstChild; n != null; n = n.NextSibling)
- {
- toNode.AppendChild(ImportNodeInternal(n, deep));
- }
- }
-
- // Microsoft extensions
-
- // Gets the XmlNameTable associated with this
- // implementation.
- public XmlNameTable NameTable
- {
- get { return _implementation.NameTable; }
- }
-
- // Creates a XmlAttribute with the specified Prefix, LocalName,
- // and NamespaceURI.
- public virtual XmlAttribute CreateAttribute(string prefix, string localName, string namespaceURI)
- {
- return new XmlAttribute(AddAttrXmlName(prefix, localName, namespaceURI, null), this);
- }
-
- protected internal virtual XmlAttribute CreateDefaultAttribute(string prefix, string localName, string namespaceURI)
- {
- return new XmlUnspecifiedAttribute(prefix, localName, namespaceURI, this);
- }
-
- public virtual XmlElement CreateElement(string prefix, string localName, string namespaceURI)
- {
- XmlElement elem = new XmlElement(AddXmlName(prefix, localName, namespaceURI, null), true, this);
- if (!IsLoading)
- AddDefaultAttributes(elem);
- return elem;
- }
-
- // Gets or sets a value indicating whether to preserve whitespace.
- public bool PreserveWhitespace
- {
- get { return _preserveWhitespace; }
- set { _preserveWhitespace = value; }
- }
-
- // Gets a value indicating whether the node is read-only.
- public override bool IsReadOnly
- {
- get { return false; }
- }
-
- internal XmlNamedNodeMap Entities
- {
- get
- {
- if (_entities == null)
- _entities = new XmlNamedNodeMap(this);
- return _entities;
- }
- set { _entities = value; }
- }
-
- internal bool IsLoading
- {
- get { return _isLoading; }
- set { _isLoading = value; }
- }
-
- internal bool ActualLoadingStatus
- {
- get { return _actualLoadingStatus; }
- set { _actualLoadingStatus = value; }
- }
-
-
- // Creates a XmlNode with the specified XmlNodeType, Prefix, Name, and NamespaceURI.
- public virtual XmlNode CreateNode(XmlNodeType type, string prefix, string name, string namespaceURI)
- {
- switch (type)
- {
- case XmlNodeType.Element:
- if (prefix != null)
- return CreateElement(prefix, name, namespaceURI);
- else
- return CreateElement(name, namespaceURI);
-
- case XmlNodeType.Attribute:
- if (prefix != null)
- return CreateAttribute(prefix, name, namespaceURI);
- else
- return CreateAttribute(name, namespaceURI);
-
- case XmlNodeType.Text:
- return CreateTextNode(string.Empty);
-
- case XmlNodeType.CDATA:
- return CreateCDataSection(string.Empty);
-
- case XmlNodeType.EntityReference:
- return CreateEntityReference(name);
-
- case XmlNodeType.ProcessingInstruction:
- return CreateProcessingInstruction(name, string.Empty);
-
- case XmlNodeType.XmlDeclaration:
- return CreateXmlDeclaration("1.0", null, null);
-
- case XmlNodeType.Comment:
- return CreateComment(string.Empty);
-
- case XmlNodeType.DocumentFragment:
- return CreateDocumentFragment();
-
- case XmlNodeType.DocumentType:
- return CreateDocumentType(name, string.Empty, string.Empty, string.Empty);
-
- case XmlNodeType.Document:
- return new XmlDocument();
-
- case XmlNodeType.SignificantWhitespace:
- return CreateSignificantWhitespace(string.Empty);
-
- case XmlNodeType.Whitespace:
- return CreateWhitespace(string.Empty);
-
- default:
- throw new ArgumentException(string.Format(ResXml.Arg_CannotCreateNode, type));
- }
- }
-
- // Creates an XmlNode with the specified node type, Name, and
- // NamespaceURI.
- public virtual XmlNode CreateNode(string nodeTypeString, string name, string namespaceURI)
- {
- return CreateNode(ConvertToNodeType(nodeTypeString), name, namespaceURI);
- }
-
- // Creates an XmlNode with the specified XmlNodeType, Name, and
- // NamespaceURI.
- public virtual XmlNode CreateNode(XmlNodeType type, string name, string namespaceURI)
- {
- return CreateNode(type, null, name, namespaceURI);
- }
-
- // Creates an XmlNode object based on the information in the XmlReader.
- // The reader must be positioned on a node or attribute.
- // [PermissionSetAttribute( SecurityAction.InheritanceDemand, Name = "FullTrust" )]
- public virtual XmlNode ReadNode(XmlReader reader)
- {
- XmlNode node = null;
- try
- {
- IsLoading = true;
- XmlLoader loader = new XmlLoader();
- node = loader.ReadCurrentNode(this, reader);
- }
- finally
- {
- IsLoading = false;
- }
- return node;
- }
-
- internal XmlNodeType ConvertToNodeType(string nodeTypeString)
- {
- if (nodeTypeString == "element")
- {
- return XmlNodeType.Element;
- }
- else if (nodeTypeString == "attribute")
- {
- return XmlNodeType.Attribute;
- }
- else if (nodeTypeString == "text")
- {
- return XmlNodeType.Text;
- }
- else if (nodeTypeString == "cdatasection")
- {
- return XmlNodeType.CDATA;
- }
- else if (nodeTypeString == "entityreference")
- {
- return XmlNodeType.EntityReference;
- }
- else if (nodeTypeString == "entity")
- {
- return XmlNodeType.Entity;
- }
- else if (nodeTypeString == "processinginstruction")
- {
- return XmlNodeType.ProcessingInstruction;
- }
- else if (nodeTypeString == "comment")
- {
- return XmlNodeType.Comment;
- }
- else if (nodeTypeString == "document")
- {
- return XmlNodeType.Document;
- }
- else if (nodeTypeString == "documenttype")
- {
- return XmlNodeType.DocumentType;
- }
- else if (nodeTypeString == "documentfragment")
- {
- return XmlNodeType.DocumentFragment;
- }
- else if (nodeTypeString == "notation")
- {
- return XmlNodeType.Notation;
- }
- else if (nodeTypeString == "significantwhitespace")
- {
- return XmlNodeType.SignificantWhitespace;
- }
- else if (nodeTypeString == "whitespace")
- {
- return XmlNodeType.Whitespace;
- }
- throw new ArgumentException(string.Format(ResXml.Xdom_Invalid_NT_String, nodeTypeString));
- }
-
-
- private XmlTextReader SetupReader(XmlTextReader tr)
- {
- tr.XmlValidatingReaderCompatibilityMode = true;
- tr.EntityHandling = EntityHandling.ExpandCharEntities;
- if (this.HasSetResolver)
- tr.XmlResolver = GetResolver();
- return tr;
- }
-
- // Loads the XML document from the specified URL.
- // [ResourceConsumption(ResourceScope.Machine)]
- // [ResourceExposure(ResourceScope.Machine)]
- public virtual void Load(string filename)
- {
- XmlTextReader reader = SetupReader(new XmlTextReader(filename, NameTable));
- try
- {
- Load(reader);
- }
- finally
- {
- reader.Close();
- }
- }
-
- public virtual void Load(Stream inStream)
- {
- XmlTextReader reader = SetupReader(new XmlTextReader(inStream, NameTable));
- try
- {
- Load(reader);
- }
- finally
- {
- reader.Impl.Close(false);
- }
- }
-
- // Loads the XML document from the specified TextReader.
- public virtual void Load(TextReader txtReader)
- {
- XmlTextReader reader = SetupReader(new XmlTextReader(txtReader, NameTable));
- try
- {
- Load(reader);
- }
- finally
- {
- reader.Impl.Close(false);
- }
- }
-
- // Loads the XML document from the specified XmlReader.
- public virtual void Load(XmlReader reader)
- {
- try
- {
- IsLoading = true;
- _actualLoadingStatus = true;
- RemoveAll();
- fEntRefNodesPresent = false;
- fCDataNodesPresent = false;
- _reportValidity = true;
-
- XmlLoader loader = new XmlLoader();
- loader.Load(this, reader, _preserveWhitespace);
- }
- finally
- {
- IsLoading = false;
- _actualLoadingStatus = false;
-
- // Ensure the bit is still on after loading a dtd
- _reportValidity = true;
- }
- }
-
- // Loads the XML document from the specified string.
- public virtual void LoadXml(string xml)
- {
- XmlTextReader reader = SetupReader(new XmlTextReader(new StringReader(xml), NameTable));
- try
- {
- Load(reader);
- }
- finally
- {
- reader.Close();
- }
- }
-
- //TextEncoding is the one from XmlDeclaration if there is any
- internal Encoding TextEncoding
- {
- get
- {
- if (Declaration != null)
- {
- string value = Declaration.Encoding;
- if (value.Length > 0)
- {
- return System.Text.Encoding.GetEncoding(value);
- }
- }
- return null;
- }
- }
-
- public override string InnerText
- {
- set
- {
- throw new InvalidOperationException(ResXml.Xdom_Document_Innertext);
- }
- }
-
- public override string InnerXml
- {
- get
- {
- return base.InnerXml;
- }
- set
- {
- LoadXml(value);
- }
- }
-
- // Saves the XML document to the specified file.
- //Saves out the to the file with exact content in the XmlDocument.
- // [ResourceConsumption(ResourceScope.Machine)]
- // [ResourceExposure(ResourceScope.Machine)]
- public virtual void Save(string filename)
- {
- if (DocumentElement == null)
- throw new XmlException(ResXml.Xml_InvalidXmlDocument, ResXml.Xdom_NoRootEle);
- XmlDOMTextWriter xw = new XmlDOMTextWriter(filename, TextEncoding);
- try
- {
- if (_preserveWhitespace == false)
- xw.Formatting = Formatting.Indented;
- WriteTo(xw);
- xw.Flush();
- }
- finally
- {
- xw.Close();
- }
- }
-
- //Saves out the to the file with exact content in the XmlDocument.
- public virtual void Save(Stream outStream)
- {
- XmlDOMTextWriter xw = new XmlDOMTextWriter(outStream, TextEncoding);
- if (_preserveWhitespace == false)
- xw.Formatting = Formatting.Indented;
- WriteTo(xw);
- xw.Flush();
- }
-
- // Saves the XML document to the specified TextWriter.
- //
- //Saves out the file with xmldeclaration which has encoding value equal to
- //that of textwriter's encoding
- public virtual void Save(TextWriter writer)
- {
- XmlDOMTextWriter xw = new XmlDOMTextWriter(writer);
- if (_preserveWhitespace == false)
- xw.Formatting = Formatting.Indented;
- Save(xw);
- }
-
- // Saves the XML document to the specified XmlWriter.
- //
- //Saves out the file with xmldeclaration which has encoding value equal to
- //that of textwriter's encoding
- public virtual void Save(XmlWriter w)
- {
- XmlNode n = this.FirstChild;
- if (n == null)
- return;
- if (w.WriteState == WriteState.Start)
- {
- if (n is XmlDeclaration)
- {
- if (Standalone.Length == 0)
- w.WriteStartDocument();
- else if (Standalone == "yes")
- w.WriteStartDocument(true);
- else if (Standalone == "no")
- w.WriteStartDocument(false);
- n = n.NextSibling;
- }
- else
- {
- w.WriteStartDocument();
- }
- }
- while (n != null)
- {
- //Debug.Assert( n.NodeType != XmlNodeType.XmlDeclaration );
- n.WriteTo(w);
- n = n.NextSibling;
- }
- w.Flush();
- }
-
- // Saves the node to the specified XmlWriter.
- //
- //Writes out the to the file with exact content in the XmlDocument.
- public override void WriteTo(XmlWriter w)
- {
- WriteContentTo(w);
- }
-
- // Saves all the children of the node to the specified XmlWriter.
- //
- //Writes out the to the file with exact content in the XmlDocument.
- public override void WriteContentTo(XmlWriter xw)
- {
- foreach (XmlNode n in this)
- {
- n.WriteTo(xw);
- }
- }
-
- public void Validate(ValidationEventHandler validationEventHandler)
- {
- Validate(validationEventHandler, this);
- }
-
- public void Validate(ValidationEventHandler validationEventHandler, XmlNode nodeToValidate)
- {
- if (_schemas == null || _schemas.Count == 0)
- { //Should we error
- throw new InvalidOperationException(ResXml.XmlDocument_NoSchemaInfo);
- }
- XmlDocument parentDocument = nodeToValidate.Document;
- if (parentDocument != this)
- {
- throw new ArgumentException(string.Format(ResXml.XmlDocument_NodeNotFromDocument, "nodeToValidate"));
- }
- if (nodeToValidate == this)
- {
- _reportValidity = false;
- }
- DocumentSchemaValidator validator = new DocumentSchemaValidator(this, _schemas, validationEventHandler);
- validator.Validate(nodeToValidate);
- if (nodeToValidate == this)
- {
- _reportValidity = true;
- }
- }
-
- public event XmlNodeChangedEventHandler NodeInserting
- {
- add
- {
- _onNodeInsertingDelegate += value;
- }
- remove
- {
- _onNodeInsertingDelegate -= value;
- }
- }
-
- public event XmlNodeChangedEventHandler NodeInserted
- {
- add
- {
- _onNodeInsertedDelegate += value;
- }
- remove
- {
- _onNodeInsertedDelegate -= value;
- }
- }
-
- public event XmlNodeChangedEventHandler NodeRemoving
- {
- add
- {
- _onNodeRemovingDelegate += value;
- }
- remove
- {
- _onNodeRemovingDelegate -= value;
- }
- }
-
- public event XmlNodeChangedEventHandler NodeRemoved
- {
- add
- {
- _onNodeRemovedDelegate += value;
- }
- remove
- {
- _onNodeRemovedDelegate -= value;
- }
- }
-
- public event XmlNodeChangedEventHandler NodeChanging
- {
- add
- {
- _onNodeChangingDelegate += value;
- }
- remove
- {
- _onNodeChangingDelegate -= value;
- }
- }
-
- public event XmlNodeChangedEventHandler NodeChanged
- {
- add
- {
- _onNodeChangedDelegate += value;
- }
- remove
- {
- _onNodeChangedDelegate -= value;
- }
- }
-
- internal override XmlNodeChangedEventArgs GetEventArgs(XmlNode node, XmlNode oldParent, XmlNode newParent, string oldValue, string newValue, XmlNodeChangedAction action)
- {
- _reportValidity = false;
-
- switch (action)
- {
- case XmlNodeChangedAction.Insert:
- if (_onNodeInsertingDelegate == null && _onNodeInsertedDelegate == null)
- {
- return null;
- }
- break;
- case XmlNodeChangedAction.Remove:
- if (_onNodeRemovingDelegate == null && _onNodeRemovedDelegate == null)
- {
- return null;
- }
- break;
- case XmlNodeChangedAction.Change:
- if (_onNodeChangingDelegate == null && _onNodeChangedDelegate == null)
- {
- return null;
- }
- break;
- }
- return new XmlNodeChangedEventArgs(node, oldParent, newParent, oldValue, newValue, action);
- }
-
- internal XmlNodeChangedEventArgs GetInsertEventArgsForLoad(XmlNode node, XmlNode newParent)
- {
- if (_onNodeInsertingDelegate == null && _onNodeInsertedDelegate == null)
- {
- return null;
- }
- string nodeValue = node.Value;
- return new XmlNodeChangedEventArgs(node, null, newParent, nodeValue, nodeValue, XmlNodeChangedAction.Insert);
- }
-
- internal override void BeforeEvent(XmlNodeChangedEventArgs args)
- {
- if (args != null)
- {
- switch (args.Action)
- {
- case XmlNodeChangedAction.Insert:
- if (_onNodeInsertingDelegate != null)
- _onNodeInsertingDelegate(this, args);
- break;
-
- case XmlNodeChangedAction.Remove:
- if (_onNodeRemovingDelegate != null)
- _onNodeRemovingDelegate(this, args);
- break;
-
- case XmlNodeChangedAction.Change:
- if (_onNodeChangingDelegate != null)
- _onNodeChangingDelegate(this, args);
- break;
- }
- }
- }
-
- internal override void AfterEvent(XmlNodeChangedEventArgs args)
- {
- if (args != null)
- {
- switch (args.Action)
- {
- case XmlNodeChangedAction.Insert:
- if (_onNodeInsertedDelegate != null)
- _onNodeInsertedDelegate(this, args);
- break;
-
- case XmlNodeChangedAction.Remove:
- if (_onNodeRemovedDelegate != null)
- _onNodeRemovedDelegate(this, args);
- break;
-
- case XmlNodeChangedAction.Change:
- if (_onNodeChangedDelegate != null)
- _onNodeChangedDelegate(this, args);
- break;
- }
- }
- }
-
- // The function such through schema info to find out if there exists a default attribute with passed in names in the passed in element
- // If so, return the newly created default attribute (with children tree);
- // Otherwise, return null.
-
- internal XmlAttribute GetDefaultAttribute(XmlElement elem, string attrPrefix, string attrLocalname, string attrNamespaceURI)
- {
- SchemaInfo schInfo = DtdSchemaInfo;
- SchemaElementDecl ed = GetSchemaElementDecl(elem);
- if (ed != null && ed.AttDefs != null)
- {
- IDictionaryEnumerator attrDefs = ed.AttDefs.GetEnumerator();
- while (attrDefs.MoveNext())
- {
- SchemaAttDef attdef = (SchemaAttDef)attrDefs.Value;
- if (attdef.Presence == SchemaDeclBase.Use.Default ||
- attdef.Presence == SchemaDeclBase.Use.Fixed)
- {
- if (attdef.Name.Name == attrLocalname)
- {
- if ((schInfo.SchemaType == SchemaType.DTD && attdef.Name.Namespace == attrPrefix) ||
- (schInfo.SchemaType != SchemaType.DTD && attdef.Name.Namespace == attrNamespaceURI))
- {
- //find a def attribute with the same name, build a default attribute and return
- XmlAttribute defattr = PrepareDefaultAttribute(attdef, attrPrefix, attrLocalname, attrNamespaceURI);
- return defattr;
- }
- }
- }
- }
- }
- return null;
- }
-
- internal String Version
- {
- get
- {
- XmlDeclaration decl = Declaration;
- if (decl != null)
- return decl.Version;
- return null;
- }
- }
-
- internal String Encoding
- {
- get
- {
- XmlDeclaration decl = Declaration;
- if (decl != null)
- return decl.Encoding;
- return null;
- }
- }
-
- internal String Standalone
- {
- get
- {
- XmlDeclaration decl = Declaration;
- if (decl != null)
- return decl.Standalone;
- return null;
- }
- }
-
- internal XmlEntity GetEntityNode(String name)
- {
- if (DocumentType != null)
- {
- XmlNamedNodeMap entites = DocumentType.Entities;
- if (entites != null)
- return (XmlEntity)(entites.GetNamedItem(name));
- }
- return null;
- }
-
- public override IXmlSchemaInfo SchemaInfo
- {
- get
- {
- if (_reportValidity)
- {
- XmlElement documentElement = DocumentElement;
- if (documentElement != null)
- {
- switch (documentElement.SchemaInfo.Validity)
- {
- case XmlSchemaValidity.Valid:
- return ValidSchemaInfo;
- case XmlSchemaValidity.Invalid:
- return InvalidSchemaInfo;
- }
- }
- }
- return NotKnownSchemaInfo;
- }
- }
-
- public override String BaseURI
- {
- get { return baseURI; }
- }
-
- internal void SetBaseURI(String inBaseURI)
- {
- baseURI = inBaseURI;
- }
-
- internal override XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
- {
- Debug.Assert(doc == this);
-
- if (!IsValidChildType(newChild.NodeType))
- throw new InvalidOperationException(ResXml.Xdom_Node_Insert_TypeConflict);
-
- if (!CanInsertAfter(newChild, LastChild))
- throw new InvalidOperationException(ResXml.Xdom_Node_Insert_Location);
-
- XmlNodeChangedEventArgs args = GetInsertEventArgsForLoad(newChild, this);
-
- if (args != null)
- BeforeEvent(args);
-
- XmlLinkedNode newNode = (XmlLinkedNode)newChild;
-
- if (_lastChild == null)
- {
- newNode.next = newNode;
- }
- else
- {
- newNode.next = _lastChild.next;
- _lastChild.next = newNode;
- }
-
- _lastChild = newNode;
- newNode.SetParentForLoad(this);
-
- if (args != null)
- AfterEvent(args);
-
- return newNode;
- }
-
- internal override XPathNodeType XPNodeType { get { return XPathNodeType.Root; } }
-
- internal bool HasEntityReferences
- {
- get
- {
- return fEntRefNodesPresent;
- }
- }
-
- internal XmlAttribute NamespaceXml
- {
- get
- {
- if (_namespaceXml == null)
- {
- _namespaceXml = new XmlAttribute(AddAttrXmlName(strXmlns, strXml, strReservedXmlns, null), this);
- _namespaceXml.Value = strReservedXml;
- }
- return _namespaceXml;
- }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDocumentFragment.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDocumentFragment.cs
deleted file mode 100644
index 6e678b82136..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDocumentFragment.cs
+++ /dev/null
@@ -1,200 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-// DocumentFragment is a "lightweight" or "minimal"
-// Document object. It is very common to want to be able to
-// extract a portion of a document's tree or to create a new fragment of a
-// document. Imagine implementing a user command like cut or rearranging a
-// document by moving fragments around. It is desirable to have an object
-// which can hold such fragments and it is quite natural to use a Node for
-// this purpose. While it is true that a Document object could
-// fulfil this role, a Document object can potentially be a
-// heavyweight object, depending on the underlying implementation. What is
-// really needed for this is a very lightweight object.
-// DocumentFragment is such an object.
-// Furthermore, various operations -- such as inserting nodes as children
-// of another Node -- may take DocumentFragment
-// objects as arguments; this results in all the child nodes of the
-// DocumentFragment being moved to the child list of this node.
-//
The children of a DocumentFragment node are zero or more
-// nodes representing the tops of any sub-trees defining the structure of the
-// document. DocumentFragment nodes do not need to be
-// well-formed XML documents (although they do need to follow the rules
-// imposed upon well-formed XML parsed entities, which can have multiple top
-// nodes). For example, a DocumentFragment might have only one
-// child and that child node could be a Text node. Such a
-// structure model represents neither an HTML document nor a well-formed XML
-// document.
-//
When a DocumentFragment is inserted into a
-// Document (or indeed any other Node that may take
-// children) the children of the DocumentFragment and not the
-// DocumentFragment itself are inserted into the
-// Node. This makes the DocumentFragment very
-// useful when the user wishes to create nodes that are siblings; the
-// DocumentFragment acts as the parent of these nodes so that the
-// user can use the standard methods from the Node interface,
-// such as insertBefore() and appendChild().
-
-namespace Microsoft.Xml
-{
- using System;
-
-
- using System.Diagnostics;
- using Microsoft.Xml.XPath;
-
- // Represents a lightweight object that is useful for tree insert
- // operations.
- public class XmlDocumentFragment : XmlNode
- {
- private XmlLinkedNode _lastChild;
-
- protected internal XmlDocumentFragment(XmlDocument ownerDocument) : base()
- {
- if (ownerDocument == null)
- throw new ArgumentException(ResXml.Xdom_Node_Null_Doc);
- parentNode = ownerDocument;
- }
-
- // Gets the name of the node.
- public override String Name
- {
- get { return OwnerDocument.strDocumentFragmentName; }
- }
-
- // Gets the name of the current node without the namespace prefix.
- public override String LocalName
- {
- get { return OwnerDocument.strDocumentFragmentName; }
- }
-
- // Gets the type of the current node.
- public override XmlNodeType NodeType
- {
- get { return XmlNodeType.DocumentFragment; }
- }
-
- // Gets the parent of this node (for nodes that can have parents).
- public override XmlNode ParentNode
- {
- get { return null; }
- }
-
- // Gets the XmlDocument that contains this node.
- public override XmlDocument OwnerDocument
- {
- get
- {
- return (XmlDocument)parentNode;
- }
- }
-
- // Gets or sets the markup representing just
- // the children of this node.
- public override string InnerXml
- {
- get
- {
- return base.InnerXml;
- }
- set
- {
- RemoveAll();
- XmlLoader loader = new XmlLoader();
- //Hack that the content is the same element
- loader.ParsePartialContent(this, value, XmlNodeType.Element);
- }
- }
-
- // Creates a duplicate of this node.
- public override XmlNode CloneNode(bool deep)
- {
- Debug.Assert(OwnerDocument != null);
- XmlDocument doc = OwnerDocument;
- XmlDocumentFragment clone = doc.CreateDocumentFragment();
- if (deep)
- clone.CopyChildren(doc, this, deep);
- return clone;
- }
-
- internal override bool IsContainer
- {
- get { return true; }
- }
-
- internal override XmlLinkedNode LastNode
- {
- get { return _lastChild; }
- set { _lastChild = value; }
- }
-
- internal override bool IsValidChildType(XmlNodeType type)
- {
- switch (type)
- {
- case XmlNodeType.Element:
- case XmlNodeType.Text:
- case XmlNodeType.EntityReference:
- case XmlNodeType.Comment:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- case XmlNodeType.ProcessingInstruction:
- case XmlNodeType.CDATA:
- return true;
-
- case XmlNodeType.XmlDeclaration:
- //if there is an XmlDeclaration node, it has to be the first node;
- XmlNode firstNode = FirstChild;
- if (firstNode == null || firstNode.NodeType != XmlNodeType.XmlDeclaration)
- return true;
- else
- return false; //not allowed to insert a second XmlDeclaration node
- default:
- return false;
- }
- }
- internal override bool CanInsertAfter(XmlNode newChild, XmlNode refChild)
- {
- Debug.Assert(newChild != null); //should be checked that newChild is not null before this function call
- if (newChild.NodeType == XmlNodeType.XmlDeclaration)
- {
- if (refChild == null)
- {
- //append at the end
- return (LastNode == null);
- }
- else
- return false;
- }
- return true;
- }
-
- internal override bool CanInsertBefore(XmlNode newChild, XmlNode refChild)
- {
- Debug.Assert(newChild != null); //should be checked that newChild is not null before this function call
- if (newChild.NodeType == XmlNodeType.XmlDeclaration)
- {
- return (refChild == null || refChild == FirstChild);
- }
- return true;
- }
-
- // Saves the node to the specified XmlWriter.
- public override void WriteTo(XmlWriter w)
- {
- WriteContentTo(w);
- }
-
- // Saves all the children of the node to the specified XmlWriter.
- public override void WriteContentTo(XmlWriter w)
- {
- foreach (XmlNode n in this)
- {
- n.WriteTo(w);
- }
- }
-
- internal override XPathNodeType XPNodeType { get { return XPathNodeType.Root; } }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDocumentType.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDocumentType.cs
deleted file mode 100644
index a76c9187a7b..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDocumentType.cs
+++ /dev/null
@@ -1,160 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
-
- using Microsoft.Xml.Schema;
- using System.Diagnostics;
-
- // Contains information associated with the document type declaration.
- public class XmlDocumentType : XmlLinkedNode
- {
- private string _name;
- private string _publicId;
- private string _systemId;
- private string _internalSubset;
- private bool _namespaces;
- private XmlNamedNodeMap _entities;
- private XmlNamedNodeMap _notations;
-
- // parsed DTD
- private SchemaInfo _schemaInfo;
-
- protected internal XmlDocumentType(string name, string publicId, string systemId, string internalSubset, XmlDocument doc) : base(doc)
- {
- _name = name;
- _publicId = publicId;
- _systemId = systemId;
- _namespaces = true;
- _internalSubset = internalSubset;
- Debug.Assert(doc != null);
- if (!doc.IsLoading)
- {
- doc.IsLoading = true;
- XmlLoader loader = new XmlLoader();
- loader.ParseDocumentType(this); //will edit notation nodes, etc.
- doc.IsLoading = false;
- }
- }
-
- // Gets the name of the node.
- public override string Name
- {
- get { return _name; }
- }
-
- // Gets the name of the current node without the namespace prefix.
- public override string LocalName
- {
- get { return _name; }
- }
-
- // Gets the type of the current node.
- public override XmlNodeType NodeType
- {
- get { return XmlNodeType.DocumentType; }
- }
-
- // Creates a duplicate of this node.
- public override XmlNode CloneNode(bool deep)
- {
- Debug.Assert(OwnerDocument != null);
- return OwnerDocument.CreateDocumentType(_name, _publicId, _systemId, _internalSubset);
- }
-
- //
- // Microsoft extensions
- //
-
- // Gets a value indicating whether the node is read-only.
- public override bool IsReadOnly
- {
- get
- {
- return true; // Make entities and notations readonly
- }
- }
-
- // Gets the collection of XmlEntity nodes declared in the document type declaration.
- public XmlNamedNodeMap Entities
- {
- get
- {
- if (_entities == null)
- _entities = new XmlNamedNodeMap(this);
-
- return _entities;
- }
- }
-
- // Gets the collection of XmlNotation nodes present in the document type declaration.
- public XmlNamedNodeMap Notations
- {
- get
- {
- if (_notations == null)
- _notations = new XmlNamedNodeMap(this);
-
- return _notations;
- }
- }
-
- //
- // DOM Level 2
- //
-
- // Gets the value of the public identifier on the DOCTYPE declaration.
- public string PublicId
- {
- get { return _publicId; }
- }
-
- // Gets the value of
- // the system identifier on the DOCTYPE declaration.
- public string SystemId
- {
- get { return _systemId; }
- }
-
- // Gets the entire value of the DTD internal subset
- // on the DOCTYPE declaration.
- public string InternalSubset
- {
- get { return _internalSubset; }
- }
-
- internal bool ParseWithNamespaces
- {
- get { return _namespaces; }
- set { _namespaces = value; }
- }
-
- // Saves the node to the specified XmlWriter.
- public override void WriteTo(XmlWriter w)
- {
- w.WriteDocType(_name, _publicId, _systemId, _internalSubset);
- }
-
- // Saves all the children of the node to the specified XmlWriter.
- public override void WriteContentTo(XmlWriter w)
- {
- // Intentionally do nothing
- }
-
- internal SchemaInfo DtdSchemaInfo
- {
- get
- {
- return _schemaInfo;
- }
- set
- {
- _schemaInfo = value;
- }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDomTextWriter.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDomTextWriter.cs
deleted file mode 100644
index 3895aae7dba..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlDomTextWriter.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
- using System.IO;
- using System.Text;
- using System.Runtime.Versioning;
-
- // Represents a writer that will make it possible to work with prefixes even
- // if the namespace is not specified.
- // This is not possible with XmlTextWriter. But this class inherits XmlTextWriter.
- internal class XmlDOMTextWriter : XmlTextWriter
- {
- public XmlDOMTextWriter(Stream w, Encoding encoding) : base(w, encoding)
- {
- }
-
- // [ResourceConsumption(ResourceScope.Machine)]
- // [ResourceExposure(ResourceScope.Machine)]
- public XmlDOMTextWriter(String filename, Encoding encoding) : base(filename, encoding)
- {
- }
-
- public XmlDOMTextWriter(TextWriter w) : base(w)
- {
- }
-
- // Overrides the baseclass implementation so that emptystring prefixes do
- // do not fail if namespace is not specified.
- public override void WriteStartElement(string prefix, string localName, string ns)
- {
- if ((ns.Length == 0) && (prefix.Length != 0))
- prefix = "";
-
- base.WriteStartElement(prefix, localName, ns);
- }
-
- // Overrides the baseclass implementation so that emptystring prefixes do
- // do not fail if namespace is not specified.
- public override void WriteStartAttribute(string prefix, string localName, string ns)
- {
- if ((ns.Length == 0) && (prefix.Length != 0))
- prefix = "";
-
- base.WriteStartAttribute(prefix, localName, ns);
- }
- }
-}
-
-
-
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlElement.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlElement.cs
deleted file mode 100644
index 4fa44b6e152..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlElement.cs
+++ /dev/null
@@ -1,638 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using Microsoft.Xml.Schema;
-using Microsoft.Xml.XPath;
-using System.Collections;
-using System.Diagnostics;
-using System.Globalization;
-
-namespace Microsoft.Xml
-{
- using System;
-
- // Represents an element.
- public class XmlElement : XmlLinkedNode
- {
- private XmlName _name;
- private XmlAttributeCollection _attributes;
- private XmlLinkedNode _lastChild; // == this for empty elements otherwise it is the last child
-
- internal XmlElement(XmlName name, bool empty, XmlDocument doc) : base(doc)
- {
- Debug.Assert(name != null);
- this.parentNode = null;
- if (!doc.IsLoading)
- {
- XmlDocument.CheckName(name.Prefix);
- XmlDocument.CheckName(name.LocalName);
- }
- if (name.LocalName.Length == 0)
- throw new ArgumentException(ResXml.Xdom_Empty_LocalName);
- _name = name;
- if (empty)
- {
- _lastChild = this;
- }
- }
-
- protected internal XmlElement(string prefix, string localName, string namespaceURI, XmlDocument doc)
- : this(doc.AddXmlName(prefix, localName, namespaceURI, null), true, doc)
- {
- }
-
- internal XmlName XmlName
- {
- get { return _name; }
- set { _name = value; }
- }
-
- // Creates a duplicate of this node.
- public override XmlNode CloneNode(bool deep)
- {
- Debug.Assert(OwnerDocument != null);
- XmlDocument doc = OwnerDocument;
- bool OrigLoadingStatus = doc.IsLoading;
- doc.IsLoading = true;
- XmlElement element = doc.CreateElement(Prefix, LocalName, NamespaceURI);
- doc.IsLoading = OrigLoadingStatus;
- if (element.IsEmpty != this.IsEmpty)
- element.IsEmpty = this.IsEmpty;
-
- if (HasAttributes)
- {
- foreach (XmlAttribute attr in Attributes)
- {
- XmlAttribute newAttr = (XmlAttribute)(attr.CloneNode(true));
- if (attr is XmlUnspecifiedAttribute && attr.Specified == false)
- ((XmlUnspecifiedAttribute)newAttr).SetSpecified(false);
- element.Attributes.InternalAppendAttribute(newAttr);
- }
- }
- if (deep)
- element.CopyChildren(doc, this, deep);
-
- return element;
- }
-
- // Gets the name of the node.
- public override string Name
- {
- get { return _name.Name; }
- }
-
- // Gets the name of the current node without the namespace prefix.
- public override string LocalName
- {
- get { return _name.LocalName; }
- }
-
- // Gets the namespace URI of this node.
- public override string NamespaceURI
- {
- get { return _name.NamespaceURI; }
- }
-
- // Gets or sets the namespace prefix of this node.
- public override string Prefix
- {
- get { return _name.Prefix; }
- set { _name = _name.OwnerDocument.AddXmlName(value, LocalName, NamespaceURI, SchemaInfo); }
- }
-
- // Gets the type of the current node.
- public override XmlNodeType NodeType
- {
- get { return XmlNodeType.Element; }
- }
-
- public override XmlNode ParentNode
- {
- get
- {
- return this.parentNode;
- }
- }
-
- // Gets the XmlDocument that contains this node.
- public override XmlDocument OwnerDocument
- {
- get
- {
- return _name.OwnerDocument;
- }
- }
-
- internal override bool IsContainer
- {
- get { return true; }
- }
-
- //the function is provided only at Load time to speed up Load process
- internal override XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
- {
- XmlNodeChangedEventArgs args = doc.GetInsertEventArgsForLoad(newChild, this);
-
- if (args != null)
- doc.BeforeEvent(args);
-
- XmlLinkedNode newNode = (XmlLinkedNode)newChild;
-
- if (_lastChild == null
- || _lastChild == this)
- { // if LastNode == null
- newNode.next = newNode;
- _lastChild = newNode; // LastNode = newNode;
- newNode.SetParentForLoad(this);
- }
- else
- {
- XmlLinkedNode refNode = _lastChild; // refNode = LastNode;
- newNode.next = refNode.next;
- refNode.next = newNode;
- _lastChild = newNode; // LastNode = newNode;
- if (refNode.IsText
- && newNode.IsText)
- {
- NestTextNodes(refNode, newNode);
- }
- else
- {
- newNode.SetParentForLoad(this);
- }
- }
-
- if (args != null)
- doc.AfterEvent(args);
-
- return newNode;
- }
-
- // Gets or sets whether the element does not have any children.
- public bool IsEmpty
- {
- get
- {
- return _lastChild == this;
- }
-
- set
- {
- if (value)
- {
- if (_lastChild != this)
- {
- RemoveAllChildren();
- _lastChild = this;
- }
- }
- else
- {
- if (_lastChild == this)
- {
- _lastChild = null;
- }
- }
- }
- }
-
- internal override XmlLinkedNode LastNode
- {
- get
- {
- return _lastChild == this ? null : _lastChild;
- }
-
- set
- {
- _lastChild = value;
- }
- }
-
- internal override bool IsValidChildType(XmlNodeType type)
- {
- switch (type)
- {
- case XmlNodeType.Element:
- case XmlNodeType.Text:
- case XmlNodeType.EntityReference:
- case XmlNodeType.Comment:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- case XmlNodeType.ProcessingInstruction:
- case XmlNodeType.CDATA:
- return true;
-
- default:
- return false;
- }
- }
-
-
- // Gets a XmlAttributeCollection containing the list of attributes for this node.
- public override XmlAttributeCollection Attributes
- {
- get
- {
- if (_attributes == null)
- {
- lock (OwnerDocument.objLock)
- {
- if (_attributes == null)
- {
- _attributes = new XmlAttributeCollection(this);
- }
- }
- }
-
- return _attributes;
- }
- }
-
- // Gets a value indicating whether the current node
- // has any attributes.
- public virtual bool HasAttributes
- {
- get
- {
- if (_attributes == null)
- return false;
- else
- return _attributes.Count > 0;
- }
- }
-
- // Returns the value for the attribute with the specified name.
- public virtual string GetAttribute(string name)
- {
- XmlAttribute attr = GetAttributeNode(name);
- if (attr != null)
- return attr.Value;
- return String.Empty;
- }
-
- // Sets the value of the attribute
- // with the specified name.
- public virtual void SetAttribute(string name, string value)
- {
- XmlAttribute attr = GetAttributeNode(name);
- if (attr == null)
- {
- attr = OwnerDocument.CreateAttribute(name);
- attr.Value = value;
- Attributes.InternalAppendAttribute(attr);
- }
- else
- {
- attr.Value = value;
- }
- }
-
- // Removes an attribute by name.
- public virtual void RemoveAttribute(string name)
- {
- if (HasAttributes)
- Attributes.RemoveNamedItem(name);
- }
-
- // Returns the XmlAttribute with the specified name.
- public virtual XmlAttribute GetAttributeNode(string name)
- {
- if (HasAttributes)
- return Attributes[name];
- return null;
- }
-
- // Adds the specified XmlAttribute.
- public virtual XmlAttribute SetAttributeNode(XmlAttribute newAttr)
- {
- if (newAttr.OwnerElement != null)
- throw new InvalidOperationException(ResXml.Xdom_Attr_InUse);
- return (XmlAttribute)Attributes.SetNamedItem(newAttr);
- }
-
- // Removes the specified XmlAttribute.
- public virtual XmlAttribute RemoveAttributeNode(XmlAttribute oldAttr)
- {
- if (HasAttributes)
- return (XmlAttribute)Attributes.Remove(oldAttr);
- return null;
- }
-
- // Returns a XmlNodeList containing
- // a list of all descendant elements that match the specified name.
- public virtual XmlNodeList GetElementsByTagName(string name)
- {
- return new XmlElementList(this, name);
- }
-
- //
- // DOM Level 2
- //
-
- // Returns the value for the attribute with the specified LocalName and NamespaceURI.
- public virtual string GetAttribute(string localName, string namespaceURI)
- {
- XmlAttribute attr = GetAttributeNode(localName, namespaceURI);
- if (attr != null)
- return attr.Value;
- return String.Empty;
- }
-
- // Sets the value of the attribute with the specified name
- // and namespace.
- public virtual string SetAttribute(string localName, string namespaceURI, string value)
- {
- XmlAttribute attr = GetAttributeNode(localName, namespaceURI);
- if (attr == null)
- {
- attr = OwnerDocument.CreateAttribute(string.Empty, localName, namespaceURI);
- attr.Value = value;
- Attributes.InternalAppendAttribute(attr);
- }
- else
- {
- attr.Value = value;
- }
-
- return value;
- }
-
- // Removes an attribute specified by LocalName and NamespaceURI.
- public virtual void RemoveAttribute(string localName, string namespaceURI)
- {
- //Debug.Assert(namespaceURI != null);
- RemoveAttributeNode(localName, namespaceURI);
- }
-
- // Returns the XmlAttribute with the specified LocalName and NamespaceURI.
- public virtual XmlAttribute GetAttributeNode(string localName, string namespaceURI)
- {
- //Debug.Assert(namespaceURI != null);
- if (HasAttributes)
- return Attributes[localName, namespaceURI];
- return null;
- }
-
- // Adds the specified XmlAttribute.
- public virtual XmlAttribute SetAttributeNode(string localName, string namespaceURI)
- {
- XmlAttribute attr = GetAttributeNode(localName, namespaceURI);
- if (attr == null)
- {
- attr = OwnerDocument.CreateAttribute(string.Empty, localName, namespaceURI);
- Attributes.InternalAppendAttribute(attr);
- }
- return attr;
- }
-
- // Removes the XmlAttribute specified by LocalName and NamespaceURI.
- public virtual XmlAttribute RemoveAttributeNode(string localName, string namespaceURI)
- {
- //Debug.Assert(namespaceURI != null);
- if (HasAttributes)
- {
- XmlAttribute attr = GetAttributeNode(localName, namespaceURI);
- Attributes.Remove(attr);
- return attr;
- }
- return null;
- }
-
- // Returns a XmlNodeList containing
- // a list of all descendant elements that match the specified name.
- public virtual XmlNodeList GetElementsByTagName(string localName, string namespaceURI)
- {
- //Debug.Assert(namespaceURI != null);
- return new XmlElementList(this, localName, namespaceURI);
- }
-
- // Determines whether the current node has the specified attribute.
- public virtual bool HasAttribute(string name)
- {
- return GetAttributeNode(name) != null;
- }
-
- // Determines whether the current node has the specified
- // attribute from the specified namespace.
- public virtual bool HasAttribute(string localName, string namespaceURI)
- {
- return GetAttributeNode(localName, namespaceURI) != null;
- }
-
- // Saves the current node to the specified XmlWriter.
- public override void WriteTo(XmlWriter w)
- {
- if (GetType() == typeof(XmlElement))
- {
- // Use the non-recursive version (for XmlElement only)
- WriteElementTo(w, this);
- }
- else
- {
- // Use the (potentially) recursive version
- WriteStartElement(w);
-
- if (IsEmpty)
- {
- w.WriteEndElement();
- }
- else
- {
- WriteContentTo(w);
- w.WriteFullEndElement();
- }
- }
- }
-
- // This method is copied from Microsoft.Xml.Linq.ElementWriter.WriteElement but adapted to DOM
- private static void WriteElementTo(XmlWriter writer, XmlElement e)
- {
- XmlNode root = e;
- XmlNode n = e;
- while (true)
- {
- e = n as XmlElement;
- // Only use the inlined write logic for XmlElement, not for derived classes
- if (e != null && e.GetType() == typeof(XmlElement))
- {
- // Write the element
- e.WriteStartElement(writer);
- // Write the element's content
- if (e.IsEmpty)
- {
- // No content; use a short end element
- writer.WriteEndElement();
- }
- else if (e._lastChild == null)
- {
- // No actual content; use a full end element
- writer.WriteFullEndElement();
- }
- else
- {
- // There are child node(s); move to first child
- n = e.FirstChild;
- Debug.Assert(n != null);
- continue;
- }
- }
- else
- {
- // Use virtual dispatch (might recurse)
- n.WriteTo(writer);
- }
- // Go back to the parent after writing the last child
- while (n != root && n == n.ParentNode.LastChild)
- {
- n = n.ParentNode;
- Debug.Assert(n != null);
- writer.WriteFullEndElement();
- }
- if (n == root)
- break;
- n = n.NextSibling;
- Debug.Assert(n != null);
- }
- }
-
- // Writes the start of the element (and its attributes) to the specified writer
- private void WriteStartElement(XmlWriter w)
- {
- w.WriteStartElement(Prefix, LocalName, NamespaceURI);
-
- if (HasAttributes)
- {
- XmlAttributeCollection attrs = Attributes;
- for (int i = 0; i < attrs.Count; i += 1)
- {
- XmlAttribute attr = attrs[i];
- attr.WriteTo(w);
- }
- }
- }
-
- // Saves all the children of the node to the specified XmlWriter.
- public override void WriteContentTo(XmlWriter w)
- {
- for (XmlNode node = FirstChild; node != null; node = node.NextSibling)
- {
- node.WriteTo(w);
- }
- }
-
- // Removes the attribute node with the specified index from the attribute collection.
- public virtual XmlNode RemoveAttributeAt(int i)
- {
- if (HasAttributes)
- return _attributes.RemoveAt(i);
- return null;
- }
-
- // Removes all attributes from the element.
- public virtual void RemoveAllAttributes()
- {
- if (HasAttributes)
- {
- _attributes.RemoveAll();
- }
- }
-
- // Removes all the children and/or attributes
- // of the current node.
- public override void RemoveAll()
- {
- //remove all the children
- base.RemoveAll();
- //remove all the attributes
- RemoveAllAttributes();
- }
-
- internal void RemoveAllChildren()
- {
- base.RemoveAll();
- }
-
- public override IXmlSchemaInfo SchemaInfo
- {
- get
- {
- return _name;
- }
- }
-
- // Gets or sets the markup representing just
- // the children of this node.
- public override string InnerXml
- {
- get
- {
- return base.InnerXml;
- }
- set
- {
- RemoveAllChildren();
- XmlLoader loader = new XmlLoader();
- loader.LoadInnerXmlElement(this, value);
- }
- }
-
- // Gets or sets the concatenated values of the
- // node and all its children.
- public override string InnerText
- {
- get
- {
- return base.InnerText;
- }
- set
- {
- XmlLinkedNode linkedNode = LastNode;
- if (linkedNode != null && //there is one child
- linkedNode.NodeType == XmlNodeType.Text && //which is text node
- linkedNode.next == linkedNode) // and it is the only child
- {
- //this branch is for perf reason, event fired when TextNode.Value is changed.
- linkedNode.Value = value;
- }
- else
- {
- RemoveAllChildren();
- AppendChild(OwnerDocument.CreateTextNode(value));
- }
- }
- }
-
- public override XmlNode NextSibling
- {
- get
- {
- if (this.parentNode != null
- && this.parentNode.LastNode != this)
- return next;
- return null;
- }
- }
-
- internal override void SetParent(XmlNode node)
- {
- this.parentNode = node;
- }
-
- internal override XPathNodeType XPNodeType { get { return XPathNodeType.Element; } }
-
- internal override string XPLocalName { get { return LocalName; } }
-
- internal override string GetXPAttribute(string localName, string ns)
- {
- if (ns == OwnerDocument.strReservedXmlns)
- return null;
- XmlAttribute attr = GetAttributeNode(localName, ns);
- if (attr != null)
- return attr.Value;
- return string.Empty;
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlElementList.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlElementList.cs
deleted file mode 100644
index a33bc6f3e56..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlElementList.cs
+++ /dev/null
@@ -1,399 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
- using System.Collections;
- using System.Diagnostics;
-
- internal class XmlElementList : XmlNodeList
- {
- private string _asterisk;
- private int _changeCount; //recording the total number that the dom tree has been changed ( insertion and deletetion )
- //the member vars below are saved for further reconstruction
- private string _name; //only one of 2 string groups will be initialized depends on which constructor is called.
- private string _localName;
- private string _namespaceURI;
- private XmlNode _rootNode;
- // the memeber vars belwo serves the optimization of accessing of the elements in the list
- private int _curInd; // -1 means the starting point for a new search round
- private XmlNode _curElem; // if sets to rootNode, means the starting point for a new search round
- private bool _empty; // whether the list is empty
- private bool _atomized; //whether the localname and namespaceuri are aomized
- private int _matchCount; // cached list count. -1 means it needs reconstruction
-
- private WeakReference _listener; // XmlElementListListener
-
- private XmlElementList(XmlNode parent)
- {
- Debug.Assert(parent != null);
- Debug.Assert(parent.NodeType == XmlNodeType.Element || parent.NodeType == XmlNodeType.Document);
- _rootNode = parent;
- Debug.Assert(parent.Document != null);
- _curInd = -1;
- _curElem = _rootNode;
- _changeCount = 0;
- _empty = false;
- _atomized = true;
- _matchCount = -1;
- // This can be a regular reference, but it would cause some kind of loop inside the GC
- _listener = new WeakReference(new XmlElementListListener(parent.Document, this));
- }
-
- ~XmlElementList()
- {
- Dispose(false);
- }
-
- internal void ConcurrencyCheck(XmlNodeChangedEventArgs args)
- {
- if (_atomized == false)
- {
- XmlNameTable nameTable = _rootNode.Document.NameTable;
- _localName = nameTable.Add(_localName);
- _namespaceURI = nameTable.Add(_namespaceURI);
- _atomized = true;
- }
- if (IsMatch(args.Node))
- {
- _changeCount++;
- _curInd = -1;
- _curElem = _rootNode;
- if (args.Action == XmlNodeChangedAction.Insert)
- _empty = false;
- }
- _matchCount = -1;
- }
-
- internal XmlElementList(XmlNode parent, string name) : this(parent)
- {
- Debug.Assert(parent.Document != null);
- XmlNameTable nt = parent.Document.NameTable;
- Debug.Assert(nt != null);
- _asterisk = nt.Add("*");
- _name = nt.Add(name);
- _localName = null;
- _namespaceURI = null;
- }
-
- internal XmlElementList(XmlNode parent, string localName, string namespaceURI) : this(parent)
- {
- Debug.Assert(parent.Document != null);
- XmlNameTable nt = parent.Document.NameTable;
- Debug.Assert(nt != null);
- _asterisk = nt.Add("*");
- _localName = nt.Get(localName);
- _namespaceURI = nt.Get(namespaceURI);
- if ((_localName == null) || (_namespaceURI == null))
- {
- _empty = true;
- _atomized = false;
- _localName = localName;
- _namespaceURI = namespaceURI;
- }
- _name = null;
- }
-
- internal int ChangeCount
- {
- get { return _changeCount; }
- }
-
- // return the next element node that is in PreOrder
- private XmlNode NextElemInPreOrder(XmlNode curNode)
- {
- Debug.Assert(curNode != null);
- //For preorder walking, first try its child
- XmlNode retNode = curNode.FirstChild;
- if (retNode == null)
- {
- //if no child, the next node forward will the be the NextSibling of the first ancestor which has NextSibling
- //so, first while-loop find out such an ancestor (until no more ancestor or the ancestor is the rootNode
- retNode = curNode;
- while (retNode != null
- && retNode != _rootNode
- && retNode.NextSibling == null)
- {
- retNode = retNode.ParentNode;
- }
- //then if such ancestor exists, set the retNode to its NextSibling
- if (retNode != null && retNode != _rootNode)
- retNode = retNode.NextSibling;
- }
- if (retNode == _rootNode)
- //if reach the rootNode, consider having walked through the whole tree and no more element after the curNode
- retNode = null;
- return retNode;
- }
-
- // return the previous element node that is in PreOrder
- private XmlNode PrevElemInPreOrder(XmlNode curNode)
- {
- Debug.Assert(curNode != null);
- //For preorder walking, the previous node will be the right-most node in the tree of PreviousSibling of the curNode
- XmlNode retNode = curNode.PreviousSibling;
- // so if the PreviousSibling is not null, going through the tree down to find the right-most node
- while (retNode != null)
- {
- if (retNode.LastChild == null)
- break;
- retNode = retNode.LastChild;
- }
- // if no PreviousSibling, the previous node will be the curNode's parentNode
- if (retNode == null)
- retNode = curNode.ParentNode;
- // if the final retNode is rootNode, consider having walked through the tree and no more previous node
- if (retNode == _rootNode)
- retNode = null;
- return retNode;
- }
-
- // if the current node a matching element node
- private bool IsMatch(XmlNode curNode)
- {
- if (curNode.NodeType == XmlNodeType.Element)
- {
- if (_name != null)
- {
- if (Ref.Equal(_name, _asterisk) || Ref.Equal(curNode.Name, _name))
- return true;
- }
- else
- {
- if (
- (Ref.Equal(_localName, _asterisk) || Ref.Equal(curNode.LocalName, _localName)) &&
- (Ref.Equal(_namespaceURI, _asterisk) || curNode.NamespaceURI == _namespaceURI)
- )
- {
- return true;
- }
- }
- }
- return false;
- }
-
- private XmlNode GetMatchingNode(XmlNode n, bool bNext)
- {
- Debug.Assert(n != null);
- XmlNode node = n;
- do
- {
- if (bNext)
- node = NextElemInPreOrder(node);
- else
- node = PrevElemInPreOrder(node);
- } while (node != null && !IsMatch(node));
- return node;
- }
-
- private XmlNode GetNthMatchingNode(XmlNode n, bool bNext, int nCount)
- {
- Debug.Assert(n != null);
- XmlNode node = n;
- for (int ind = 0; ind < nCount; ind++)
- {
- node = GetMatchingNode(node, bNext);
- if (node == null)
- return null;
- }
- return node;
- }
-
- //the function is for the enumerator to find out the next available matching element node
- public XmlNode GetNextNode(XmlNode n)
- {
- if (_empty == true)
- return null;
- XmlNode node = (n == null) ? _rootNode : n;
- return GetMatchingNode(node, true);
- }
-
- public override XmlNode Item(int index)
- {
- if (_rootNode == null || index < 0)
- return null;
-
- if (_empty == true)
- return null;
- if (_curInd == index)
- return _curElem;
- int nDiff = index - _curInd;
- bool bForward = (nDiff > 0);
- if (nDiff < 0)
- nDiff = -nDiff;
- XmlNode node;
- if ((node = GetNthMatchingNode(_curElem, bForward, nDiff)) != null)
- {
- _curInd = index;
- _curElem = node;
- return _curElem;
- }
- return null;
- }
-
- public override int Count
- {
- get
- {
- if (_empty == true)
- return 0;
- if (_matchCount < 0)
- {
- int currMatchCount = 0;
- int currChangeCount = _changeCount;
- XmlNode node = _rootNode;
- while ((node = GetMatchingNode(node, true)) != null)
- {
- currMatchCount++;
- }
- if (currChangeCount != _changeCount)
- {
- return currMatchCount;
- }
- _matchCount = currMatchCount;
- }
- return _matchCount;
- }
- }
-
- public override IEnumerator GetEnumerator()
- {
- if (_empty == true)
- return new XmlEmptyElementListEnumerator(this); ;
- return new XmlElementListEnumerator(this);
- }
-
- protected override void PrivateDisposeNodeList()
- {
- GC.SuppressFinalize(this);
- Dispose(true);
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (_listener != null)
- {
- XmlElementListListener listener = (XmlElementListListener)_listener.Target;
- if (listener != null)
- {
- listener.Unregister();
- }
- _listener = null;
- }
- }
- }
-
- internal class XmlElementListEnumerator : IEnumerator
- {
- private XmlElementList _list;
- private XmlNode _curElem;
- private int _changeCount; //save the total number that the dom tree has been changed ( insertion and deletetion ) when this enumerator is created
-
- public XmlElementListEnumerator(XmlElementList list)
- {
- _list = list;
- _curElem = null;
- _changeCount = list.ChangeCount;
- }
-
- public bool MoveNext()
- {
- if (_list.ChangeCount != _changeCount)
- {
- //the number mismatch, there is new change(s) happened since last MoveNext() is called.
- throw new InvalidOperationException(ResXml.Xdom_Enum_ElementList);
- }
- else
- {
- _curElem = _list.GetNextNode(_curElem);
- }
- return _curElem != null;
- }
-
- public void Reset()
- {
- _curElem = null;
- //reset the number of changes to be synced with current dom tree as well
- _changeCount = _list.ChangeCount;
- }
-
- public object Current
- {
- get { return _curElem; }
- }
- }
-
- internal class XmlEmptyElementListEnumerator : IEnumerator
- {
- public XmlEmptyElementListEnumerator(XmlElementList list)
- {
- }
-
- public bool MoveNext()
- {
- return false;
- }
-
- public void Reset()
- {
- }
-
- public object Current
- {
- get { return null; }
- }
- }
-
- internal class XmlElementListListener
- {
- private WeakReference _elemList;
- private XmlDocument _doc;
- private XmlNodeChangedEventHandler _nodeChangeHandler = null;
-
- internal XmlElementListListener(XmlDocument doc, XmlElementList elemList)
- {
- _doc = doc;
- _elemList = new WeakReference(elemList);
- _nodeChangeHandler = new XmlNodeChangedEventHandler(this.OnListChanged);
- doc.NodeInserted += _nodeChangeHandler;
- doc.NodeRemoved += _nodeChangeHandler;
- }
-
- private void OnListChanged(object sender, XmlNodeChangedEventArgs args)
- {
- lock (this)
- {
- if (_elemList != null)
- {
- XmlElementList el = (XmlElementList)_elemList.Target;
- if (null != el)
- {
- el.ConcurrencyCheck(args);
- }
- else
- {
- _doc.NodeInserted -= _nodeChangeHandler;
- _doc.NodeRemoved -= _nodeChangeHandler;
- _elemList = null;
- }
- }
- }
- }
-
- // This method is called from the finalizer of XmlElementList
- internal void Unregister()
- {
- lock (this)
- {
- if (_elemList != null)
- {
- _doc.NodeInserted -= _nodeChangeHandler;
- _doc.NodeRemoved -= _nodeChangeHandler;
- _elemList = null;
- }
- }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlEntity.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlEntity.cs
deleted file mode 100644
index c2242b53a0b..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlEntity.cs
+++ /dev/null
@@ -1,166 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- using System.Diagnostics;
-
- // Represents a parsed or unparsed entity in the XML document.
- public class XmlEntity : XmlNode
- {
- private string _publicId;
- private string _systemId;
- private String _notationName;
- private String _name;
- private String _unparsedReplacementStr;
- private String _baseURI;
- private XmlLinkedNode _lastChild;
- private bool _childrenFoliating;
-
- internal XmlEntity(String name, String strdata, string publicId, string systemId, String notationName, XmlDocument doc) : base(doc)
- {
- _name = doc.NameTable.Add(name);
- _publicId = publicId;
- _systemId = systemId;
- _notationName = notationName;
- _unparsedReplacementStr = strdata;
- _childrenFoliating = false;
- }
-
- // Throws an excption since an entity can not be cloned.
- public override XmlNode CloneNode(bool deep)
- {
- throw new InvalidOperationException(ResXml.Xdom_Node_Cloning);
- }
-
- //
- // Microsoft extensions
- //
-
- // Gets a value indicating whether the node is read-only.
- public override bool IsReadOnly
- {
- get
- {
- return true; // Make entities readonly
- }
- }
-
-
- // Gets the name of the node.
- public override string Name
- {
- get { return _name; }
- }
-
- // Gets the name of the node without the namespace prefix.
- public override string LocalName
- {
- get { return _name; }
- }
-
- // Gets the concatenated values of the entity node and all its children.
- // The property is read-only and when tried to be set, exception will be thrown.
- public override string InnerText
- {
- get { return base.InnerText; }
- set
- {
- throw new InvalidOperationException(ResXml.Xdom_Ent_Innertext);
- }
- }
-
- internal override bool IsContainer
- {
- get { return true; }
- }
-
- internal override XmlLinkedNode LastNode
- {
- get
- {
- if (_lastChild == null && !_childrenFoliating)
- { //expand the unparsedreplacementstring
- _childrenFoliating = true;
- //wrap the replacement string with an element
- XmlLoader loader = new XmlLoader();
- loader.ExpandEntity(this);
- }
- return _lastChild;
- }
- set { _lastChild = value; }
- }
-
- internal override bool IsValidChildType(XmlNodeType type)
- {
- return (type == XmlNodeType.Text ||
- type == XmlNodeType.Element ||
- type == XmlNodeType.ProcessingInstruction ||
- type == XmlNodeType.Comment ||
- type == XmlNodeType.CDATA ||
- type == XmlNodeType.Whitespace ||
- type == XmlNodeType.SignificantWhitespace ||
- type == XmlNodeType.EntityReference);
- }
-
- // Gets the type of the node.
- public override XmlNodeType NodeType
- {
- get { return XmlNodeType.Entity; }
- }
-
- // Gets the value of the public identifier on the entity declaration.
- public String PublicId
- {
- get { return _publicId; }
- }
-
- // Gets the value of the system identifier on the entity declaration.
- public String SystemId
- {
- get { return _systemId; }
- }
-
- // Gets the name of the optional NDATA attribute on the
- // entity declaration.
- public String NotationName
- {
- get { return _notationName; }
- }
-
- //Without override these two functions, we can't guarantee that WriteTo()/WriteContent() functions will never be called
- public override String OuterXml
- {
- get { return String.Empty; }
- }
-
- public override String InnerXml
- {
- get { return String.Empty; }
- set { throw new InvalidOperationException(ResXml.Xdom_Set_InnerXml); }
- }
-
- // Saves the node to the specified XmlWriter.
- public override void WriteTo(XmlWriter w)
- {
- }
-
- // Saves all the children of the node to the specified XmlWriter.
- public override void WriteContentTo(XmlWriter w)
- {
- }
-
- public override String BaseURI
- {
- get { return _baseURI; }
- }
-
- internal void SetBaseURI(String inBaseURI)
- {
- _baseURI = inBaseURI;
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlEntityReference.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlEntityReference.cs
deleted file mode 100644
index 5522d1277af..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlEntityReference.cs
+++ /dev/null
@@ -1,216 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-// EntityReference objects may be inserted into the structure
-// model when an entity reference is in the source document, or when the user
-// wishes to insert an entity reference. Note that character references and
-// references to predefined entities are considered to be expanded by the
-// HTML or XML processor so that characters are represented by their Unicode
-// equivalent rather than by an entity reference. Moreover, the XML
-// processor may completely expand references to entities while building the
-// structure model, instead of providing EntityReference
-// objects. If it does provide such objects, then for a given
-// EntityReference node, it may be that there is no
-// Entity node representing the referenced entity; but if such
-// an Entity exists, then the child list of the
-// EntityReference node is the same as that of the
-// Entity node. As with the Entity node, all
-// descendants of the EntityReference are readonly.
-//
The resolution of the children of the EntityReference (the
-// replacement value of the referenced Entity) may be lazily
-// evaluated; actions by the user (such as calling the
-// childNodes method on the EntityReference node)
-// are assumed to trigger the evaluation.
-
-namespace Microsoft.Xml
-{
- using System;
-
-
- using System.Diagnostics;
-
- // Represents an entity reference node.
- public class XmlEntityReference : XmlLinkedNode
- {
- private string _name;
- private XmlLinkedNode _lastChild;
-
- protected internal XmlEntityReference(string name, XmlDocument doc) : base(doc)
- {
- if (!doc.IsLoading)
- {
- if (name.Length > 0 && name[0] == '#')
- {
- throw new ArgumentException(ResXml.Xdom_InvalidCharacter_EntityReference);
- }
- }
- _name = doc.NameTable.Add(name);
- doc.fEntRefNodesPresent = true;
- }
-
- // Gets the name of the node.
- public override string Name
- {
- get { return _name; }
- }
-
- // Gets the name of the node without the namespace prefix.
- public override string LocalName
- {
- get { return _name; }
- }
-
- // Gets or sets the value of the node.
- public override String Value
- {
- get
- {
- return null;
- }
-
- set
- {
- throw new InvalidOperationException(ResXml.Xdom_EntRef_SetVal);
- }
- }
-
- // Gets the type of the node.
- public override XmlNodeType NodeType
- {
- get { return XmlNodeType.EntityReference; }
- }
-
- // Creates a duplicate of this node.
- public override XmlNode CloneNode(bool deep)
- {
- Debug.Assert(OwnerDocument != null);
- XmlEntityReference eref = OwnerDocument.CreateEntityReference(_name);
- return eref;
- }
-
- //
- // Microsoft extensions
- //
-
- // Gets a value indicating whether the node is read-only.
- public override bool IsReadOnly
- {
- get
- {
- return true; // Make entity references readonly
- }
- }
-
- internal override bool IsContainer
- {
- get { return true; }
- }
-
- internal override void SetParent(XmlNode node)
- {
- base.SetParent(node);
- if (LastNode == null && node != null && node != OwnerDocument)
- {
- //first time insert the entity reference into the tree, we should expand its children now
- XmlLoader loader = new XmlLoader();
- loader.ExpandEntityReference(this);
- }
- }
-
- internal override void SetParentForLoad(XmlNode node)
- {
- this.SetParent(node);
- }
-
- internal override XmlLinkedNode LastNode
- {
- get
- {
- return _lastChild;
- }
- set { _lastChild = value; }
- }
-
- internal override bool IsValidChildType(XmlNodeType type)
- {
- switch (type)
- {
- case XmlNodeType.Element:
- case XmlNodeType.Text:
- case XmlNodeType.EntityReference:
- case XmlNodeType.Comment:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- case XmlNodeType.ProcessingInstruction:
- case XmlNodeType.CDATA:
- return true;
-
- default:
- return false;
- }
- }
-
- // Saves the node to the specified XmlWriter.
- public override void WriteTo(XmlWriter w)
- {
- w.WriteEntityRef(_name);
- }
-
- // Saves all the children of the node to the specified XmlWriter.
- public override void WriteContentTo(XmlWriter w)
- {
- // -- eventually will the fix. commented out waiting for finalizing on the issue.
- foreach (XmlNode n in this)
- {
- n.WriteTo(w);
- } //still use the old code to generate the output
- /*
- foreach( XmlNode n in this ) {
- if ( n.NodeType != XmlNodeType.EntityReference )
- n.WriteTo( w );
- else
- n.WriteContentTo( w );
- }*/
- }
-
- public override String BaseURI
- {
- get
- {
- return OwnerDocument.BaseURI;
- }
- }
-
- private string ConstructBaseURI(string baseURI, string systemId)
- {
- if (baseURI == null)
- return systemId;
- int nCount = baseURI.LastIndexOf('/') + 1;
- string buf = baseURI;
- if (nCount > 0 && nCount < baseURI.Length)
- buf = baseURI.Substring(0, nCount);
- else if (nCount == 0)
- buf = buf + "\\";
- return (buf + systemId.Replace('\\', '/'));
- }
-
- //childrenBaseURI returns where the entity reference node's children come from
- internal String ChildBaseURI
- {
- get
- {
- //get the associate entity and return its baseUri
- XmlEntity ent = OwnerDocument.GetEntityNode(_name);
- if (ent != null)
- {
- if (ent.SystemId != null && ent.SystemId.Length > 0)
- return ConstructBaseURI(ent.BaseURI, ent.SystemId);
- else
- return ent.BaseURI;
- }
- return String.Empty;
- }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlEventChangedAction.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlEventChangedAction.cs
deleted file mode 100644
index 2c6725810c4..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlEventChangedAction.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- // Specifies the type of node change
- public enum XmlNodeChangedAction
- {
- // A node is beeing inserted in the tree.
- Insert = 0,
-
- // A node is beeing removed from the tree.
- Remove = 1,
-
- // A node value is beeing changed.
- Change = 2
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlImplementation.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlImplementation.cs
deleted file mode 100644
index 35d39b9ac77..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlImplementation.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Globalization;
-
-namespace Microsoft.Xml
-{
- using System;
-
-
- // Provides methods for performing operations that are independent of any
- // particular instance of the document object model.
- public class XmlImplementation
- {
- private XmlNameTable _nameTable;
-
- // Initializes a new instance of the XmlImplementation class.
- public XmlImplementation() : this(new NameTable())
- {
- }
-
- public XmlImplementation(XmlNameTable nt)
- {
- _nameTable = nt;
- }
-
- // Test if the DOM implementation implements a specific feature.
- public bool HasFeature(string strFeature, string strVersion)
- {
- if (String.Compare("XML", strFeature, StringComparison.OrdinalIgnoreCase) == 0)
- {
- if (strVersion == null || strVersion == "1.0" || strVersion == "2.0")
- return true;
- }
- return false;
- }
-
- // Creates a new XmlDocument. All documents created from the same
- // XmlImplementation object share the same name table.
- public virtual XmlDocument CreateDocument()
- {
- return new XmlDocument(this);
- }
-
- internal XmlNameTable NameTable
- {
- get { return _nameTable; }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlLinkedNode.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlLinkedNode.cs
deleted file mode 100644
index 2706a93e1f4..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlLinkedNode.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
-
- // Gets the node immediately preceeding or following this node.
- public abstract class XmlLinkedNode : XmlNode
- {
- internal XmlLinkedNode next;
-
- internal XmlLinkedNode() : base()
- {
- next = null;
- }
- internal XmlLinkedNode(XmlDocument doc) : base(doc)
- {
- next = null;
- }
-
- // Gets the node immediately preceding this node.
- public override XmlNode PreviousSibling
- {
- get
- {
- XmlNode parent = ParentNode;
- if (parent != null)
- {
- XmlNode node = parent.FirstChild;
- while (node != null)
- {
- XmlNode nextSibling = node.NextSibling;
- if (nextSibling == this)
- {
- break;
- }
- node = nextSibling;
- }
- return node;
- }
- return null;
- }
- }
-
- // Gets the node immediately following this node.
- public override XmlNode NextSibling
- {
- get
- {
- XmlNode parent = ParentNode;
- if (parent != null)
- {
- if (next != parent.FirstChild)
- return next;
- }
- return null;
- }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlLoader.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlLoader.cs
deleted file mode 100644
index c7c5ed8e8ff..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlLoader.cs
+++ /dev/null
@@ -1,1010 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- using System.IO;
- using System.Collections;
- using System.Diagnostics;
- using System.Text;
- using Microsoft.Xml.Schema;
- using System.Globalization;
-
- internal class XmlLoader
- {
- private XmlDocument _doc;
- private XmlReader _reader;
- private bool _preserveWhitespace;
-
-
- public XmlLoader()
- {
- }
-
- internal void Load(XmlDocument doc, XmlReader reader, bool preserveWhitespace)
- {
- _doc = doc;
- // perf: unwrap XmlTextReader if no one derived from it
- if (reader.GetType() == typeof(Microsoft.Xml.XmlTextReader))
- {
- _reader = ((XmlTextReader)reader).Impl;
- }
- else
- {
- _reader = reader;
- }
- _preserveWhitespace = preserveWhitespace;
- if (doc == null)
- throw new ArgumentException(ResXml.Xdom_Load_NoDocument);
- if (reader == null)
- throw new ArgumentException(ResXml.Xdom_Load_NoReader);
- doc.SetBaseURI(reader.BaseURI);
- if (reader.Settings != null
- && reader.Settings.ValidationType == ValidationType.Schema)
- {
- doc.Schemas = reader.Settings.Schemas;
- }
- if (_reader.ReadState != ReadState.Interactive)
- {
- if (!_reader.Read())
- return;
- }
- LoadDocSequence(doc);
- }
-
- //The function will start loading the document from where current XmlReader is pointing at.
- private void LoadDocSequence(XmlDocument parentDoc)
- {
- Debug.Assert(_reader != null);
- Debug.Assert(parentDoc != null);
- XmlNode node = null;
- while ((node = LoadNode(true)) != null)
- {
- parentDoc.AppendChildForLoad(node, parentDoc);
- if (!_reader.Read())
- return;
- }
- }
-
- internal XmlNode ReadCurrentNode(XmlDocument doc, XmlReader reader)
- {
- _doc = doc;
- _reader = reader;
- // WS are optional only for loading (see XmlDocument.PreserveWhitespace)
- _preserveWhitespace = true;
- if (doc == null)
- throw new ArgumentException(ResXml.Xdom_Load_NoDocument);
- if (reader == null)
- throw new ArgumentException(ResXml.Xdom_Load_NoReader);
-
- if (reader.ReadState == ReadState.Initial)
- {
- reader.Read();
- }
- if (reader.ReadState == ReadState.Interactive)
- {
- XmlNode n = LoadNode(true);
-
- // Move to the next node
- if (n.NodeType != XmlNodeType.Attribute)
- reader.Read();
-
- return n;
- }
- return null;
- }
-
- private XmlNode LoadNode(bool skipOverWhitespace)
- {
- XmlReader r = _reader;
- XmlNode parent = null;
- XmlElement element;
- IXmlSchemaInfo schemaInfo;
- do
- {
- XmlNode node = null;
- switch (r.NodeType)
- {
- case XmlNodeType.Element:
- bool fEmptyElement = r.IsEmptyElement;
- element = _doc.CreateElement(r.Prefix, r.LocalName, r.NamespaceURI);
- element.IsEmpty = fEmptyElement;
-
- if (r.MoveToFirstAttribute())
- {
- XmlAttributeCollection attributes = element.Attributes;
- do
- {
- XmlAttribute attr = LoadAttributeNode();
- attributes.Append(attr); // special case for load
- }
- while (r.MoveToNextAttribute());
- r.MoveToElement();
- }
-
- // recursively load all children.
- if (!fEmptyElement)
- {
- if (parent != null)
- {
- parent.AppendChildForLoad(element, _doc);
- }
- parent = element;
- continue;
- }
- else
- {
- schemaInfo = r.SchemaInfo;
- if (schemaInfo != null)
- {
- element.XmlName = _doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo);
- }
- node = element;
- break;
- }
-
- case XmlNodeType.EndElement:
- if (parent == null)
- {
- return null;
- }
- Debug.Assert(parent.NodeType == XmlNodeType.Element);
- schemaInfo = r.SchemaInfo;
- if (schemaInfo != null)
- {
- element = parent as XmlElement;
- if (element != null)
- {
- element.XmlName = _doc.AddXmlName(element.Prefix, element.LocalName, element.NamespaceURI, schemaInfo);
- }
- }
- if (parent.ParentNode == null)
- {
- return parent;
- }
- parent = parent.ParentNode;
- continue;
-
- case XmlNodeType.EntityReference:
- node = LoadEntityReferenceNode(false);
- break;
-
- case XmlNodeType.EndEntity:
- Debug.Assert(parent == null);
- return null;
-
- case XmlNodeType.Attribute:
- node = LoadAttributeNode();
- break;
-
- case XmlNodeType.Text:
- node = _doc.CreateTextNode(r.Value);
- break;
-
- case XmlNodeType.SignificantWhitespace:
- node = _doc.CreateSignificantWhitespace(r.Value);
- break;
-
- case XmlNodeType.Whitespace:
- if (_preserveWhitespace)
- {
- node = _doc.CreateWhitespace(r.Value);
- break;
- }
- else if (parent == null && !skipOverWhitespace)
- {
- // if called from LoadEntityReferenceNode, just return null
- return null;
- }
- else
- {
- continue;
- }
- case XmlNodeType.CDATA:
- node = _doc.CreateCDataSection(r.Value);
- break;
-
-
- case XmlNodeType.XmlDeclaration:
- node = LoadDeclarationNode();
- break;
-
- case XmlNodeType.ProcessingInstruction:
- node = _doc.CreateProcessingInstruction(r.Name, r.Value);
- break;
-
- case XmlNodeType.Comment:
- node = _doc.CreateComment(r.Value);
- break;
-
- case XmlNodeType.DocumentType:
- node = LoadDocumentTypeNode();
- break;
-
- default:
- throw UnexpectedNodeType(r.NodeType);
- }
-
- Debug.Assert(node != null);
- if (parent != null)
- {
- parent.AppendChildForLoad(node, _doc);
- }
- else
- {
- return node;
- }
- }
- while (r.Read());
-
- // when the reader ended before full subtree is read, return whatever we have created so far
- if (parent != null)
- {
- while (parent.ParentNode != null)
- {
- parent = parent.ParentNode;
- }
- }
- return parent;
- }
-
- private XmlAttribute LoadAttributeNode()
- {
- Debug.Assert(_reader.NodeType == XmlNodeType.Attribute);
-
- XmlReader r = _reader;
- if (r.IsDefault)
- {
- return LoadDefaultAttribute();
- }
-
- XmlAttribute attr = _doc.CreateAttribute(r.Prefix, r.LocalName, r.NamespaceURI);
- IXmlSchemaInfo schemaInfo = r.SchemaInfo;
- if (schemaInfo != null)
- {
- attr.XmlName = _doc.AddAttrXmlName(attr.Prefix, attr.LocalName, attr.NamespaceURI, schemaInfo);
- }
- while (r.ReadAttributeValue())
- {
- XmlNode node;
- switch (r.NodeType)
- {
- case XmlNodeType.Text:
- node = _doc.CreateTextNode(r.Value);
- break;
- case XmlNodeType.EntityReference:
- node = _doc.CreateEntityReference(r.LocalName);
- if (r.CanResolveEntity)
- {
- r.ResolveEntity();
- LoadAttributeValue(node, false);
- // Code internally relies on the fact that an EntRef nodes has at least one child (even an empty text node). Ensure that this holds true,
- // if the reader does not present any children for the ent-ref
- if (node.FirstChild == null)
- {
- node.AppendChildForLoad(_doc.CreateTextNode(string.Empty), _doc);
- }
- }
- break;
- default:
- throw UnexpectedNodeType(r.NodeType);
- }
- Debug.Assert(node != null);
- attr.AppendChildForLoad(node, _doc);
- }
-
- return attr;
- }
-
- private XmlAttribute LoadDefaultAttribute()
- {
- Debug.Assert(_reader.IsDefault);
-
- XmlReader r = _reader;
- XmlAttribute attr = _doc.CreateDefaultAttribute(r.Prefix, r.LocalName, r.NamespaceURI);
- IXmlSchemaInfo schemaInfo = r.SchemaInfo;
- if (schemaInfo != null)
- {
- attr.XmlName = _doc.AddAttrXmlName(attr.Prefix, attr.LocalName, attr.NamespaceURI, schemaInfo);
- }
-
- LoadAttributeValue(attr, false);
-
- XmlUnspecifiedAttribute defAttr = attr as XmlUnspecifiedAttribute;
- // If user overrides CreateDefaultAttribute, then attr will NOT be a XmlUnspecifiedAttribute instance.
- if (defAttr != null)
- defAttr.SetSpecified(false);
-
- return attr;
- }
-
- private void LoadAttributeValue(XmlNode parent, bool direct)
- {
- XmlReader r = _reader;
- while (r.ReadAttributeValue())
- {
- XmlNode node;
- switch (r.NodeType)
- {
- case XmlNodeType.Text:
- node = direct ? new XmlText(r.Value, _doc) : _doc.CreateTextNode(r.Value);
- break;
- case XmlNodeType.EndEntity:
- return;
- case XmlNodeType.EntityReference:
- node = direct ? new XmlEntityReference(_reader.LocalName, _doc) : _doc.CreateEntityReference(_reader.LocalName);
- if (r.CanResolveEntity)
- {
- r.ResolveEntity();
- LoadAttributeValue(node, direct);
- // Code internally relies on the fact that an EntRef nodes has at least one child (even an empty text node). Ensure that this holds true,
- // if the reader does not present any children for the ent-ref
- if (node.FirstChild == null)
- {
- node.AppendChildForLoad(direct ? new XmlText(string.Empty) : _doc.CreateTextNode(string.Empty), _doc);
- }
- }
- break;
- default:
- throw UnexpectedNodeType(r.NodeType);
- }
- Debug.Assert(node != null);
- parent.AppendChildForLoad(node, _doc);
- }
- return;
- }
-
- private XmlEntityReference LoadEntityReferenceNode(bool direct)
- {
- Debug.Assert(_reader.NodeType == XmlNodeType.EntityReference);
- XmlEntityReference eref = direct ? new XmlEntityReference(_reader.Name, _doc) : _doc.CreateEntityReference(_reader.Name);
- if (_reader.CanResolveEntity)
- {
- _reader.ResolveEntity();
- while (_reader.Read() && _reader.NodeType != XmlNodeType.EndEntity)
- {
- XmlNode node = direct ? LoadNodeDirect() : LoadNode(false);
- if (node != null)
- {
- eref.AppendChildForLoad(node, _doc);
- }
- }
- // Code internally relies on the fact that an EntRef nodes has at least one child (even an empty text node). Ensure that this holds true,
- // if the reader does not present any children for the ent-ref
- if (eref.LastChild == null)
- eref.AppendChildForLoad(_doc.CreateTextNode(string.Empty), _doc);
- }
- return eref;
- }
-
- private XmlDeclaration LoadDeclarationNode()
- {
- Debug.Assert(_reader.NodeType == XmlNodeType.XmlDeclaration);
-
- //parse data
- string version = null;
- string encoding = null;
- string standalone = null;
-
- // Try first to use the reader to get the xml decl "attributes". Since not all readers are required to support this, it is possible to have
- // implementations that do nothing
- while (_reader.MoveToNextAttribute())
- {
- switch (_reader.Name)
- {
- case "version":
- version = _reader.Value;
- break;
- case "encoding":
- encoding = _reader.Value;
- break;
- case "standalone":
- standalone = _reader.Value;
- break;
- default:
- Debug.Assert(false);
- break;
- }
- }
-
- // For readers that do not break xml decl into attributes, we must parse the xml decl ourselfs. We use version attr, b/c xml decl MUST contain
- // at least version attr, so if the reader implements them as attr, then version must be present
- if (version == null)
- ParseXmlDeclarationValue(_reader.Value, out version, out encoding, out standalone);
-
- return _doc.CreateXmlDeclaration(version, encoding, standalone);
- }
-
- private XmlDocumentType LoadDocumentTypeNode()
- {
- Debug.Assert(_reader.NodeType == XmlNodeType.DocumentType);
-
- String publicId = null;
- String systemId = null;
- String internalSubset = _reader.Value;
- String localName = _reader.LocalName;
- while (_reader.MoveToNextAttribute())
- {
- switch (_reader.Name)
- {
- case "PUBLIC":
- publicId = _reader.Value;
- break;
- case "SYSTEM":
- systemId = _reader.Value;
- break;
- }
- }
-
- XmlDocumentType dtNode = _doc.CreateDocumentType(localName, publicId, systemId, internalSubset);
-
- IDtdInfo dtdInfo = _reader.DtdInfo;
- if (dtdInfo != null)
- LoadDocumentType(dtdInfo, dtNode);
- else
- {
- //construct our own XmlValidatingReader to parse the DocumentType node so we could get Entities and notations information
- ParseDocumentType(dtNode);
- }
-
- return dtNode;
- }
-
- // LoadNodeDirect does not use creator functions on XmlDocument. It is used loading nodes that are children of entity nodes,
- // becaouse we do not want to let users extend these (if we would allow this, XmlDataDocument would have a problem, becaouse
- // they do not know that those nodes should not be mapped). It can be also used for an optimized load path when if the
- // XmlDocument is not extended if XmlDocumentType and XmlDeclaration handling is added.
- private XmlNode LoadNodeDirect()
- {
- XmlReader r = _reader;
- XmlNode parent = null;
- do
- {
- XmlNode node = null;
- switch (r.NodeType)
- {
- case XmlNodeType.Element:
- bool fEmptyElement = _reader.IsEmptyElement;
- XmlElement element = new XmlElement(_reader.Prefix, _reader.LocalName, _reader.NamespaceURI, _doc);
- element.IsEmpty = fEmptyElement;
-
- if (_reader.MoveToFirstAttribute())
- {
- XmlAttributeCollection attributes = element.Attributes;
- do
- {
- XmlAttribute attr = LoadAttributeNodeDirect();
- attributes.Append(attr); // special case for load
- } while (r.MoveToNextAttribute());
- }
-
- // recursively load all children.
- if (!fEmptyElement)
- {
- parent.AppendChildForLoad(element, _doc);
- parent = element;
- continue;
- }
- else
- {
- node = element;
- break;
- }
-
- case XmlNodeType.EndElement:
- Debug.Assert(parent.NodeType == XmlNodeType.Element);
- if (parent.ParentNode == null)
- {
- return parent;
- }
- parent = parent.ParentNode;
- continue;
-
- case XmlNodeType.EntityReference:
- node = LoadEntityReferenceNode(true);
- break;
-
- case XmlNodeType.EndEntity:
- continue;
-
- case XmlNodeType.Attribute:
- node = LoadAttributeNodeDirect();
- break;
-
- case XmlNodeType.SignificantWhitespace:
- node = new XmlSignificantWhitespace(_reader.Value, _doc);
- break;
-
- case XmlNodeType.Whitespace:
- if (_preserveWhitespace)
- {
- node = new XmlWhitespace(_reader.Value, _doc);
- }
- else
- {
- continue;
- }
- break;
-
- case XmlNodeType.Text:
- node = new XmlText(_reader.Value, _doc);
- break;
-
- case XmlNodeType.CDATA:
- node = new XmlCDataSection(_reader.Value, _doc);
- break;
-
- case XmlNodeType.ProcessingInstruction:
- node = new XmlProcessingInstruction(_reader.Name, _reader.Value, _doc);
- break;
-
- case XmlNodeType.Comment:
- node = new XmlComment(_reader.Value, _doc);
- break;
-
- default:
- throw UnexpectedNodeType(_reader.NodeType);
- }
-
- Debug.Assert(node != null);
- if (parent != null)
- {
- parent.AppendChildForLoad(node, _doc);
- }
- else
- {
- return node;
- }
- }
- while (r.Read());
-
- return null;
- }
-
- private XmlAttribute LoadAttributeNodeDirect()
- {
- XmlReader r = _reader;
- XmlAttribute attr;
- if (r.IsDefault)
- {
- XmlUnspecifiedAttribute defattr = new XmlUnspecifiedAttribute(r.Prefix, r.LocalName, r.NamespaceURI, _doc);
- LoadAttributeValue(defattr, true);
- defattr.SetSpecified(false);
- return defattr;
- }
- else
- {
- attr = new XmlAttribute(r.Prefix, r.LocalName, r.NamespaceURI, _doc);
- LoadAttributeValue(attr, true);
- return attr;
- }
- }
-
- internal void ParseDocumentType(XmlDocumentType dtNode)
- {
- XmlDocument doc = dtNode.OwnerDocument;
- //if xmlresolver is set on doc, use that one, otherwise use the default one being created by xmlvalidatingreader
- if (doc.HasSetResolver)
- ParseDocumentType(dtNode, true, doc.GetResolver());
- else
- ParseDocumentType(dtNode, false, null);
- }
-
- private void ParseDocumentType(XmlDocumentType dtNode, bool bUseResolver, XmlResolver resolver)
- {
- _doc = dtNode.OwnerDocument;
- XmlParserContext pc = new XmlParserContext(null, new XmlNamespaceManager(_doc.NameTable), null, null, null, null, _doc.BaseURI, string.Empty, XmlSpace.None);
- XmlTextReaderImpl tr = new XmlTextReaderImpl("", XmlNodeType.Element, pc);
- tr.Namespaces = dtNode.ParseWithNamespaces;
- if (bUseResolver)
- {
- tr.XmlResolver = resolver;
- }
-
- IDtdParser dtdParser = DtdParser.Create();
- XmlTextReaderImpl.DtdParserProxy proxy = new XmlTextReaderImpl.DtdParserProxy(tr);
-
- IDtdInfo dtdInfo = dtdParser.ParseFreeFloatingDtd(_doc.BaseURI, dtNode.Name, dtNode.PublicId, dtNode.SystemId, dtNode.InternalSubset, proxy);
- LoadDocumentType(dtdInfo, dtNode);
- }
-
- private void LoadDocumentType(IDtdInfo dtdInfo, XmlDocumentType dtNode)
- {
- SchemaInfo schInfo = dtdInfo as SchemaInfo;
- if (schInfo == null)
- {
- throw new XmlException(ResXml.Xml_InternalError, string.Empty);
- }
-
- dtNode.DtdSchemaInfo = schInfo;
- if (schInfo != null)
- {
- //set the schema information into the document
- _doc.DtdSchemaInfo = schInfo;
-
- // Notation hashtable
- if (schInfo.Notations != null)
- {
- foreach (SchemaNotation scNot in schInfo.Notations.Values)
- {
- dtNode.Notations.SetNamedItem(new XmlNotation(scNot.Name.Name, scNot.Pubid, scNot.SystemLiteral, _doc));
- }
- }
-
- // Entity hashtables
- if (schInfo.GeneralEntities != null)
- {
- foreach (SchemaEntity scEnt in schInfo.GeneralEntities.Values)
- {
- XmlEntity ent = new XmlEntity(scEnt.Name.Name, scEnt.Text, scEnt.Pubid, scEnt.Url, scEnt.NData.IsEmpty ? null : scEnt.NData.Name, _doc);
- ent.SetBaseURI(scEnt.DeclaredURI);
- dtNode.Entities.SetNamedItem(ent);
- }
- }
-
- if (schInfo.ParameterEntities != null)
- {
- foreach (SchemaEntity scEnt in schInfo.ParameterEntities.Values)
- {
- XmlEntity ent = new XmlEntity(scEnt.Name.Name, scEnt.Text, scEnt.Pubid, scEnt.Url, scEnt.NData.IsEmpty ? null : scEnt.NData.Name, _doc);
- ent.SetBaseURI(scEnt.DeclaredURI);
- dtNode.Entities.SetNamedItem(ent);
- }
- }
- _doc.Entities = dtNode.Entities;
-
- //extract the elements which has attribute defined as ID from the element declarations
- IDictionaryEnumerator elementDecls = schInfo.ElementDecls.GetEnumerator();
- if (elementDecls != null)
- {
- elementDecls.Reset();
- while (elementDecls.MoveNext())
- {
- SchemaElementDecl elementDecl = (SchemaElementDecl)elementDecls.Value;
- if (elementDecl.AttDefs != null)
- {
- IDictionaryEnumerator attDefs = elementDecl.AttDefs.GetEnumerator();
- while (attDefs.MoveNext())
- {
- SchemaAttDef attdef = (SchemaAttDef)attDefs.Value;
- if (attdef.Datatype.TokenizedType == XmlTokenizedType.ID)
- {
- //we only register the XmlElement based on their Prefix/LocalName and skip the namespace
- _doc.AddIdInfo(
- _doc.AddXmlName(elementDecl.Prefix, elementDecl.Name.Name, string.Empty, null),
- _doc.AddAttrXmlName(attdef.Prefix, attdef.Name.Name, string.Empty, null));
- break;
- }
- }
- }
- }
- }
- }
- }
-#pragma warning restore 618
-
- private XmlParserContext GetContext(XmlNode node)
- {
- String lang = null;
- XmlSpace spaceMode = XmlSpace.None;
- XmlDocumentType docType = _doc.DocumentType;
- String baseURI = _doc.BaseURI;
- //constructing xmlnamespace
- Hashtable prefixes = new Hashtable();
- XmlNameTable nt = _doc.NameTable;
- XmlNamespaceManager mgr = new XmlNamespaceManager(nt);
- bool bHasDefXmlnsAttr = false;
-
- // Process all xmlns, xmlns:prefix, xml:space and xml:lang attributes
- while (node != null && node != _doc)
- {
- if (node is XmlElement && ((XmlElement)node).HasAttributes)
- {
- mgr.PushScope();
- foreach (XmlAttribute attr in ((XmlElement)node).Attributes)
- {
- if (attr.Prefix == _doc.strXmlns && prefixes.Contains(attr.LocalName) == false)
- {
- // Make sure the next time we will not add this prefix
- prefixes.Add(attr.LocalName, attr.LocalName);
- mgr.AddNamespace(attr.LocalName, attr.Value);
- }
- else if (!bHasDefXmlnsAttr && attr.Prefix.Length == 0 && attr.LocalName == _doc.strXmlns)
- {
- // Save the case xmlns="..." where xmlns is the LocalName
- mgr.AddNamespace(String.Empty, attr.Value);
- bHasDefXmlnsAttr = true;
- }
- else if (spaceMode == XmlSpace.None && attr.Prefix == _doc.strXml && attr.LocalName == _doc.strSpace)
- {
- // Save xml:space context
- if (attr.Value == "default")
- spaceMode = XmlSpace.Default;
- else if (attr.Value == "preserve")
- spaceMode = XmlSpace.Preserve;
- }
- else if (lang == null && attr.Prefix == _doc.strXml && attr.LocalName == _doc.strLang)
- {
- // Save xml:lag context
- lang = attr.Value;
- }
- }
- }
- node = node.ParentNode;
- }
- return new XmlParserContext(
- nt,
- mgr,
- (docType == null) ? null : docType.Name,
- (docType == null) ? null : docType.PublicId,
- (docType == null) ? null : docType.SystemId,
- (docType == null) ? null : docType.InternalSubset,
- baseURI,
- lang,
- spaceMode
- );
- }
-
-
-
- internal XmlNamespaceManager ParsePartialContent(XmlNode parentNode, string innerxmltext, XmlNodeType nt)
- {
- //the function shouldn't be used to set innerxml for XmlDocument node
- Debug.Assert(parentNode.NodeType != XmlNodeType.Document);
- _doc = parentNode.OwnerDocument;
- Debug.Assert(_doc != null);
- XmlParserContext pc = GetContext(parentNode);
- _reader = CreateInnerXmlReader(innerxmltext, nt, pc, _doc);
- try
- {
- _preserveWhitespace = true;
- bool bOrigLoading = _doc.IsLoading;
- _doc.IsLoading = true;
-
- if (nt == XmlNodeType.Entity)
- {
- XmlNode node = null;
- while (_reader.Read() && (node = LoadNodeDirect()) != null)
- {
- parentNode.AppendChildForLoad(node, _doc);
- }
- }
- else
- {
- XmlNode node = null;
- while (_reader.Read() && (node = LoadNode(true)) != null)
- {
- parentNode.AppendChildForLoad(node, _doc);
- }
- }
- _doc.IsLoading = bOrigLoading;
- }
- finally
- {
- _reader.Close();
- }
- return pc.NamespaceManager;
- }
-
- internal void LoadInnerXmlElement(XmlElement node, string innerxmltext)
- {
- //construct a tree underneth the node
- XmlNamespaceManager mgr = ParsePartialContent(node, innerxmltext, XmlNodeType.Element);
- //remove the duplicate namesapce
- if (node.ChildNodes.Count > 0)
- RemoveDuplicateNamespace((XmlElement)node, mgr, false);
- }
-
- internal void LoadInnerXmlAttribute(XmlAttribute node, string innerxmltext)
- {
- ParsePartialContent(node, innerxmltext, XmlNodeType.Attribute);
- }
-
-
- private void RemoveDuplicateNamespace(XmlElement elem, XmlNamespaceManager mgr, bool fCheckElemAttrs)
- {
- //remove the duplicate attributes on current node first
- mgr.PushScope();
- XmlAttributeCollection attrs = elem.Attributes;
- int cAttrs = attrs.Count;
- if (fCheckElemAttrs && cAttrs > 0)
- {
- for (int i = cAttrs - 1; i >= 0; --i)
- {
- XmlAttribute attr = attrs[i];
- if (attr.Prefix == _doc.strXmlns)
- {
- string nsUri = mgr.LookupNamespace(attr.LocalName);
- if (nsUri != null)
- {
- if (attr.Value == nsUri)
- elem.Attributes.RemoveNodeAt(i);
- }
- else
- {
- // Add this namespace, so it we will behave corectly when setting "" as
- // InnerXml on this foo elem where foo is like this ""
- // If do not do this, then we will remove the inner p prefix definition and will let the 1st p to be in scope for
- // the subsequent InnerXml_set or setting an EntRef inside.
- mgr.AddNamespace(attr.LocalName, attr.Value);
- }
- }
- else if (attr.Prefix.Length == 0 && attr.LocalName == _doc.strXmlns)
- {
- string nsUri = mgr.DefaultNamespace;
- if (nsUri != null)
- {
- if (attr.Value == nsUri)
- elem.Attributes.RemoveNodeAt(i);
- }
- else
- {
- // Add this namespace, so it we will behave corectly when setting "" as
- // InnerXml on this foo elem where foo is like this ""
- // If do not do this, then we will remove the inner p prefix definition and will let the 1st p to be in scope for
- // the subsequent InnerXml_set or setting an EntRef inside.
- mgr.AddNamespace(attr.LocalName, attr.Value);
- }
- }
- }
- }
- //now recursively remove the duplicate attributes on the children
- XmlNode child = elem.FirstChild;
- while (child != null)
- {
- XmlElement childElem = child as XmlElement;
- if (childElem != null)
- RemoveDuplicateNamespace(childElem, mgr, true);
- child = child.NextSibling;
- }
- mgr.PopScope();
- }
-
- private String EntitizeName(String name)
- {
- return "&" + name + ";";
- }
-
- //The function is called when expanding the entity when its children being asked
- internal void ExpandEntity(XmlEntity ent)
- {
- ParsePartialContent(ent, EntitizeName(ent.Name), XmlNodeType.Entity);
- }
-
- //The function is called when expanding the entity ref. ( inside XmlEntityReference.SetParent )
- internal void ExpandEntityReference(XmlEntityReference eref)
- {
- //when the ent ref is not associated w/ an entity, append an empty string text node as child
- _doc = eref.OwnerDocument;
- bool bOrigLoadingState = _doc.IsLoading;
- _doc.IsLoading = true;
- switch (eref.Name)
- {
- case "lt":
- eref.AppendChildForLoad(_doc.CreateTextNode("<"), _doc);
- _doc.IsLoading = bOrigLoadingState;
- return;
- case "gt":
- eref.AppendChildForLoad(_doc.CreateTextNode(">"), _doc);
- _doc.IsLoading = bOrigLoadingState;
- return;
- case "amp":
- eref.AppendChildForLoad(_doc.CreateTextNode("&"), _doc);
- _doc.IsLoading = bOrigLoadingState;
- return;
- case "apos":
- eref.AppendChildForLoad(_doc.CreateTextNode("'"), _doc);
- _doc.IsLoading = bOrigLoadingState;
- return;
- case "quot":
- eref.AppendChildForLoad(_doc.CreateTextNode("\""), _doc);
- _doc.IsLoading = bOrigLoadingState;
- return;
- }
-
- XmlNamedNodeMap entities = _doc.Entities;
- foreach (XmlEntity ent in entities)
- {
- if (Ref.Equal(ent.Name, eref.Name))
- {
- ParsePartialContent(eref, EntitizeName(eref.Name), XmlNodeType.EntityReference);
- return;
- }
- }
- //no fit so far
- if (!(_doc.ActualLoadingStatus))
- {
- eref.AppendChildForLoad(_doc.CreateTextNode(""), _doc);
- _doc.IsLoading = bOrigLoadingState;
- }
- else
- {
- _doc.IsLoading = bOrigLoadingState;
- throw new XmlException(ResXml.Xml_UndeclaredParEntity, eref.Name);
- }
- }
-
-#pragma warning disable 618
- // Creates a XmlValidatingReader suitable for parsing InnerXml strings
- private XmlReader CreateInnerXmlReader(String xmlFragment, XmlNodeType nt, XmlParserContext context, XmlDocument doc)
- {
- XmlNodeType contentNT = nt;
- if (contentNT == XmlNodeType.Entity || contentNT == XmlNodeType.EntityReference)
- contentNT = XmlNodeType.Element;
-
- XmlTextReaderImpl tr = new XmlTextReaderImpl(xmlFragment, contentNT, context);
- tr.XmlValidatingReaderCompatibilityMode = true;
- if (doc.HasSetResolver)
- {
- tr.XmlResolver = doc.GetResolver();
- }
- if (!(doc.ActualLoadingStatus))
- {
- tr.DisableUndeclaredEntityCheck = true;
- }
- Debug.Assert(tr.EntityHandling == EntityHandling.ExpandCharEntities);
-
- XmlDocumentType dtdNode = doc.DocumentType;
- if (dtdNode != null)
- {
- tr.Namespaces = dtdNode.ParseWithNamespaces;
- if (dtdNode.DtdSchemaInfo != null)
- {
- tr.SetDtdInfo(dtdNode.DtdSchemaInfo);
- }
- else
- {
- IDtdParser dtdParser = DtdParser.Create();
- XmlTextReaderImpl.DtdParserProxy proxy = new XmlTextReaderImpl.DtdParserProxy(tr);
-
- IDtdInfo dtdInfo = dtdParser.ParseFreeFloatingDtd(context.BaseURI, context.DocTypeName, context.PublicId, context.SystemId, context.InternalSubset, proxy);
-
- // TODO: Change all of XmlDocument to IDtdInfo interfaces
- dtdNode.DtdSchemaInfo = dtdInfo as SchemaInfo;
- tr.SetDtdInfo(dtdInfo);
- }
- }
-
- if (nt == XmlNodeType.Entity || nt == XmlNodeType.EntityReference)
- {
- tr.Read(); //this will skip the first element "wrapper"
- tr.ResolveEntity();
- }
- return tr;
- }
-#pragma warning restore 618
-
- internal static void ParseXmlDeclarationValue(string strValue, out string version, out string encoding, out string standalone)
- {
- version = null;
- encoding = null;
- standalone = null;
- XmlTextReaderImpl tempreader = new XmlTextReaderImpl(strValue, (XmlParserContext)null);
- try
- {
- tempreader.Read();
- //get version info.
- if (tempreader.MoveToAttribute("version"))
- version = tempreader.Value;
- //get encoding info
- if (tempreader.MoveToAttribute("encoding"))
- encoding = tempreader.Value;
- //get standalone info
- if (tempreader.MoveToAttribute("standalone"))
- standalone = tempreader.Value;
- }
- finally
- {
- tempreader.Close();
- }
- }
-
- static internal Exception UnexpectedNodeType(XmlNodeType nodetype)
- {
- return new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, ResXml.Xml_UnexpectedNodeType, nodetype.ToString()));
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlName.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlName.cs
deleted file mode 100644
index bc9726d15b8..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlName.cs
+++ /dev/null
@@ -1,317 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- using System.Text;
- using System.Diagnostics;
- using Microsoft.Xml.Schema;
-
- internal class XmlName : IXmlSchemaInfo
- {
- private string _prefix;
- private string _localName;
- private string _ns;
- private string _name;
- private int _hashCode;
- internal XmlDocument ownerDoc;
- internal XmlName next;
-
- public static XmlName Create(string prefix, string localName, string ns, int hashCode, XmlDocument ownerDoc, XmlName next, IXmlSchemaInfo schemaInfo)
- {
- if (schemaInfo == null)
- {
- return new XmlName(prefix, localName, ns, hashCode, ownerDoc, next);
- }
- else
- {
- return new XmlNameEx(prefix, localName, ns, hashCode, ownerDoc, next, schemaInfo);
- }
- }
-
- internal XmlName(string prefix, string localName, string ns, int hashCode, XmlDocument ownerDoc, XmlName next)
- {
- _prefix = prefix;
- _localName = localName;
- _ns = ns;
- _name = null;
- _hashCode = hashCode;
- this.ownerDoc = ownerDoc;
- this.next = next;
- }
-
- public string LocalName
- {
- get
- {
- return _localName;
- }
- }
-
- public string NamespaceURI
- {
- get
- {
- return _ns;
- }
- }
-
- public string Prefix
- {
- get
- {
- return _prefix;
- }
- }
-
- public int HashCode
- {
- get
- {
- return _hashCode;
- }
- }
-
- public XmlDocument OwnerDocument
- {
- get
- {
- return ownerDoc;
- }
- }
-
- public string Name
- {
- get
- {
- if (_name == null)
- {
- Debug.Assert(_prefix != null);
- if (_prefix.Length > 0)
- {
- if (_localName.Length > 0)
- {
- string n = string.Concat(_prefix, ":", _localName);
- lock (ownerDoc.NameTable)
- {
- if (_name == null)
- {
- _name = ownerDoc.NameTable.Add(n);
- }
- }
- }
- else
- {
- _name = _prefix;
- }
- }
- else
- {
- _name = _localName;
- }
- Debug.Assert(Ref.Equal(_name, ownerDoc.NameTable.Get(_name)));
- }
- return _name;
- }
- }
-
- public virtual XmlSchemaValidity Validity
- {
- get
- {
- return XmlSchemaValidity.NotKnown;
- }
- }
-
- public virtual bool IsDefault
- {
- get
- {
- return false;
- }
- }
-
- public virtual bool IsNil
- {
- get
- {
- return false;
- }
- }
-
- public virtual XmlSchemaSimpleType MemberType
- {
- get
- {
- return null;
- }
- }
-
- public virtual XmlSchemaType SchemaType
- {
- get
- {
- return null;
- }
- }
-
- public virtual XmlSchemaElement SchemaElement
- {
- get
- {
- return null;
- }
- }
-
- public virtual XmlSchemaAttribute SchemaAttribute
- {
- get
- {
- return null;
- }
- }
-
- public virtual bool Equals(IXmlSchemaInfo schemaInfo)
- {
- return schemaInfo == null;
- }
-
- public static int GetHashCode(string name)
- {
- int hashCode = 0;
- if (name != null)
- {
- for (int i = name.Length - 1; i >= 0; i--)
- {
- char ch = name[i];
- if (ch == ':') break;
- hashCode += (hashCode << 7) ^ ch;
- }
- hashCode -= hashCode >> 17;
- hashCode -= hashCode >> 11;
- hashCode -= hashCode >> 5;
- }
- return hashCode;
- }
- }
-
- internal sealed class XmlNameEx : XmlName
- {
- private byte _flags;
- private XmlSchemaSimpleType _memberType;
- private XmlSchemaType _schemaType;
- private object _decl;
-
- // flags
- // 0,1 : Validity
- // 2 : IsDefault
- // 3 : IsNil
- private const byte ValidityMask = 0x03;
- private const byte IsDefaultBit = 0x04;
- private const byte IsNilBit = 0x08;
-
- internal XmlNameEx(string prefix, string localName, string ns, int hashCode, XmlDocument ownerDoc, XmlName next, IXmlSchemaInfo schemaInfo) : base(prefix, localName, ns, hashCode, ownerDoc, next)
- {
- SetValidity(schemaInfo.Validity);
- SetIsDefault(schemaInfo.IsDefault);
- SetIsNil(schemaInfo.IsNil);
- _memberType = schemaInfo.MemberType;
- _schemaType = schemaInfo.SchemaType;
- _decl = schemaInfo.SchemaElement != null
- ? (object)schemaInfo.SchemaElement
- : (object)schemaInfo.SchemaAttribute;
- }
-
- public override XmlSchemaValidity Validity
- {
- get
- {
- return ownerDoc.CanReportValidity ? (XmlSchemaValidity)(_flags & ValidityMask) : XmlSchemaValidity.NotKnown;
- }
- }
-
- public override bool IsDefault
- {
- get
- {
- return (_flags & IsDefaultBit) != 0;
- }
- }
-
- public override bool IsNil
- {
- get
- {
- return (_flags & IsNilBit) != 0;
- }
- }
-
- public override XmlSchemaSimpleType MemberType
- {
- get
- {
- return _memberType;
- }
- }
-
- public override XmlSchemaType SchemaType
- {
- get
- {
- return _schemaType;
- }
- }
-
- public override XmlSchemaElement SchemaElement
- {
- get
- {
- return _decl as XmlSchemaElement;
- }
- }
-
- public override XmlSchemaAttribute SchemaAttribute
- {
- get
- {
- return _decl as XmlSchemaAttribute;
- }
- }
-
- public void SetValidity(XmlSchemaValidity value)
- {
- _flags = (byte)((_flags & ~ValidityMask) | (byte)(value));
- }
-
- public void SetIsDefault(bool value)
- {
- if (value) _flags = (byte)(_flags | IsDefaultBit);
- else _flags = (byte)(_flags & ~IsDefaultBit);
- }
-
- public void SetIsNil(bool value)
- {
- if (value) _flags = (byte)(_flags | IsNilBit);
- else _flags = (byte)(_flags & ~IsNilBit);
- }
-
- public override bool Equals(IXmlSchemaInfo schemaInfo)
- {
- if (schemaInfo != null
- && schemaInfo.Validity == (XmlSchemaValidity)(_flags & ValidityMask)
- && schemaInfo.IsDefault == ((_flags & IsDefaultBit) != 0)
- && schemaInfo.IsNil == ((_flags & IsNilBit) != 0)
- && (object)schemaInfo.MemberType == (object)_memberType
- && (object)schemaInfo.SchemaType == (object)_schemaType
- && (object)schemaInfo.SchemaElement == (object)(_decl as XmlSchemaElement)
- && (object)schemaInfo.SchemaAttribute == (object)(_decl as XmlSchemaAttribute))
- {
- return true;
- }
- return false;
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNamedNodeMap.SmallXmlNodeList.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNamedNodeMap.SmallXmlNodeList.cs
deleted file mode 100644
index badc1411587..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNamedNodeMap.SmallXmlNodeList.cs
+++ /dev/null
@@ -1,199 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- using System.Collections;
-
- public partial class XmlNamedNodeMap
- {
- // Optimized to minimize space in the zero or one element cases.
- internal struct SmallXmlNodeList
- {
- // If field is null, that represents an empty list.
- // If field is non-null, but not an ArrayList, then the 'list' contains a single
- // object.
- // Otherwise, field is an ArrayList. Once the field upgrades to an ArrayList, it
- // never degrades back, even if all elements are removed.
- private object _field;
-
- public int Count
- {
- get
- {
- if (_field == null)
- return 0;
-
- ArrayList list = _field as ArrayList;
- if (list != null)
- return list.Count;
-
- return 1;
- }
- }
-
- public object this[int index]
- {
- get
- {
- if (_field == null)
- throw new ArgumentOutOfRangeException("index");
-
- ArrayList list = _field as ArrayList;
- if (list != null)
- return list[index];
-
- if (index != 0)
- throw new ArgumentOutOfRangeException("index");
-
- return _field;
- }
- }
-
- public void Add(object value)
- {
- if (_field == null)
- {
- if (value == null)
- {
- // If a single null value needs to be stored, then
- // upgrade to an ArrayList
- ArrayList temp = new ArrayList();
- temp.Add(null);
- _field = temp;
- }
- else
- _field = value;
-
- return;
- }
-
- ArrayList list = _field as ArrayList;
- if (list != null)
- {
- list.Add(value);
- }
- else
- {
- list = new ArrayList();
- list.Add(_field);
- list.Add(value);
- _field = list;
- }
- }
-
- public void RemoveAt(int index)
- {
- if (_field == null)
- throw new ArgumentOutOfRangeException("index");
-
- ArrayList list = _field as ArrayList;
- if (list != null)
- {
- list.RemoveAt(index);
- return;
- }
-
- if (index != 0)
- throw new ArgumentOutOfRangeException("index");
-
- _field = null;
- }
-
- public void Insert(int index, object value)
- {
- if (_field == null)
- {
- if (index != 0)
- throw new ArgumentOutOfRangeException("index");
- Add(value);
- return;
- }
-
- ArrayList list = _field as ArrayList;
- if (list != null)
- {
- list.Insert(index, value);
- return;
- }
-
- if (index == 0)
- {
- list = new ArrayList();
- list.Add(value);
- list.Add(_field);
- _field = list;
- }
- else if (index == 1)
- {
- list = new ArrayList();
- list.Add(_field);
- list.Add(value);
- _field = list;
- }
- else
- {
- throw new ArgumentOutOfRangeException("index");
- }
- }
-
- private class SingleObjectEnumerator : IEnumerator
- {
- private object _loneValue;
- private int _position = -1;
-
- public SingleObjectEnumerator(object value)
- {
- _loneValue = value;
- }
-
- public object Current
- {
- get
- {
- if (_position != 0)
- {
- throw new InvalidOperationException();
- }
- return _loneValue;
- }
- }
-
- public bool MoveNext()
- {
- if (_position < 0)
- {
- _position = 0;
- return true;
- }
- _position = 1;
- return false;
- }
-
- public void Reset()
- {
- _position = -1;
- }
- }
-
- public IEnumerator GetEnumerator()
- {
- if (_field == null)
- {
- return XmlDocument.EmptyEnumerator;
- }
-
- ArrayList list = _field as ArrayList;
- if (list != null)
- {
- return list.GetEnumerator();
- }
-
- return new SingleObjectEnumerator(_field);
- }
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNamedNodeMap.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNamedNodeMap.cs
deleted file mode 100644
index c18fbc67116..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNamedNodeMap.cs
+++ /dev/null
@@ -1,228 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- using System.Collections;
-
- // Represents a collection of nodes that can be accessed by name or index.
- public partial class XmlNamedNodeMap : IEnumerable
- {
- internal XmlNode parent;
- internal SmallXmlNodeList nodes;
-
- internal XmlNamedNodeMap(XmlNode parent)
- {
- this.parent = parent;
- }
-
- // Retrieves a XmlNode specified by name.
- public virtual XmlNode GetNamedItem(String name)
- {
- int offset = FindNodeOffset(name);
- if (offset >= 0)
- return (XmlNode)nodes[offset];
- return null;
- }
-
- // Adds a XmlNode using its Name property
- public virtual XmlNode SetNamedItem(XmlNode node)
- {
- if (node == null)
- return null;
-
- int offset = FindNodeOffset(node.LocalName, node.NamespaceURI);
- if (offset == -1)
- {
- AddNode(node);
- return null;
- }
- else
- {
- return ReplaceNodeAt(offset, node);
- }
- }
-
- // Removes the node specified by name.
- public virtual XmlNode RemoveNamedItem(String name)
- {
- int offset = FindNodeOffset(name);
- if (offset >= 0)
- {
- return RemoveNodeAt(offset);
- }
- return null;
- }
-
- // Gets the number of nodes in this XmlNamedNodeMap.
- public virtual int Count
- {
- get
- {
- return nodes.Count;
- }
- }
-
- // Retrieves the node at the specified index in this XmlNamedNodeMap.
- public virtual XmlNode Item(int index)
- {
- if (index < 0 || index >= nodes.Count)
- return null;
- try
- {
- return (XmlNode)nodes[index];
- }
- catch (ArgumentOutOfRangeException)
- {
- throw new IndexOutOfRangeException(ResXml.Xdom_IndexOutOfRange);
- }
- }
-
- //
- // DOM Level 2
- //
-
- // Retrieves a node specified by LocalName and NamespaceURI.
- public virtual XmlNode GetNamedItem(String localName, String namespaceURI)
- {
- int offset = FindNodeOffset(localName, namespaceURI);
- if (offset >= 0)
- return (XmlNode)nodes[offset];
- return null;
- }
-
- // Removes a node specified by local name and namespace URI.
- public virtual XmlNode RemoveNamedItem(String localName, String namespaceURI)
- {
- int offset = FindNodeOffset(localName, namespaceURI);
- if (offset >= 0)
- {
- return RemoveNodeAt(offset);
- }
- return null;
- }
-
- public virtual IEnumerator GetEnumerator()
- {
- return nodes.GetEnumerator();
- }
-
- internal int FindNodeOffset(string name)
- {
- int c = this.Count;
- for (int i = 0; i < c; i++)
- {
- XmlNode node = (XmlNode)nodes[i];
-
- if (name == node.Name)
- return i;
- }
-
- return -1;
- }
-
- internal int FindNodeOffset(string localName, string namespaceURI)
- {
- int c = this.Count;
- for (int i = 0; i < c; i++)
- {
- XmlNode node = (XmlNode)nodes[i];
-
- if (node.LocalName == localName && node.NamespaceURI == namespaceURI)
- return i;
- }
-
- return -1;
- }
-
- internal virtual XmlNode AddNode(XmlNode node)
- {
- XmlNode oldParent;
- if (node.NodeType == XmlNodeType.Attribute)
- oldParent = ((XmlAttribute)node).OwnerElement;
- else
- oldParent = node.ParentNode;
- string nodeValue = node.Value;
- XmlNodeChangedEventArgs args = parent.GetEventArgs(node, oldParent, parent, nodeValue, nodeValue, XmlNodeChangedAction.Insert);
-
- if (args != null)
- parent.BeforeEvent(args);
-
- nodes.Add(node);
- node.SetParent(parent);
-
- if (args != null)
- parent.AfterEvent(args);
-
- return node;
- }
-
- internal virtual XmlNode AddNodeForLoad(XmlNode node, XmlDocument doc)
- {
- XmlNodeChangedEventArgs args = doc.GetInsertEventArgsForLoad(node, parent);
- if (args != null)
- {
- doc.BeforeEvent(args);
- }
- nodes.Add(node);
- node.SetParent(parent);
- if (args != null)
- {
- doc.AfterEvent(args);
- }
- return node;
- }
-
- internal virtual XmlNode RemoveNodeAt(int i)
- {
- XmlNode oldNode = (XmlNode)nodes[i];
-
- string oldNodeValue = oldNode.Value;
- XmlNodeChangedEventArgs args = parent.GetEventArgs(oldNode, parent, null, oldNodeValue, oldNodeValue, XmlNodeChangedAction.Remove);
-
- if (args != null)
- parent.BeforeEvent(args);
-
- nodes.RemoveAt(i);
- oldNode.SetParent(null);
-
- if (args != null)
- parent.AfterEvent(args);
-
- return oldNode;
- }
-
- internal XmlNode ReplaceNodeAt(int i, XmlNode node)
- {
- XmlNode oldNode = RemoveNodeAt(i);
- InsertNodeAt(i, node);
- return oldNode;
- }
-
- internal virtual XmlNode InsertNodeAt(int i, XmlNode node)
- {
- XmlNode oldParent;
- if (node.NodeType == XmlNodeType.Attribute)
- oldParent = ((XmlAttribute)node).OwnerElement;
- else
- oldParent = node.ParentNode;
-
- string nodeValue = node.Value;
- XmlNodeChangedEventArgs args = parent.GetEventArgs(node, oldParent, parent, nodeValue, nodeValue, XmlNodeChangedAction.Insert);
-
- if (args != null)
- parent.BeforeEvent(args);
-
- nodes.Insert(i, node);
- node.SetParent(parent);
-
- if (args != null)
- parent.AfterEvent(args);
-
- return node;
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNode.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNode.cs
deleted file mode 100644
index 7ef1f82779d..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNode.cs
+++ /dev/null
@@ -1,1465 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
- using System.IO;
- using System.Collections;
- using System.Text;
- using System.Diagnostics;
- using Microsoft.Xml.Schema;
- using Microsoft.Xml.XPath;
- using MS.Internal.Xml.XPath;
- using System.Globalization;
-
- // Represents a single node in the document.
- [DebuggerDisplay("{debuggerDisplayProxy}")]
- public abstract class XmlNode : ICloneable, IEnumerable, IXPathNavigable
- {
- internal XmlNode parentNode; //this pointer is reused to save the userdata information, need to prevent internal user access the pointer directly.
-
- internal XmlNode()
- {
- }
-
- internal XmlNode(XmlDocument doc)
- {
- if (doc == null)
- throw new ArgumentException(ResXml.Xdom_Node_Null_Doc);
- this.parentNode = doc;
- }
-
- public virtual XPathNavigator CreateNavigator()
- {
- XmlDocument thisAsDoc = this as XmlDocument;
- if (thisAsDoc != null)
- {
- return thisAsDoc.CreateNavigator(this);
- }
- XmlDocument doc = OwnerDocument;
- Debug.Assert(doc != null);
- return doc.CreateNavigator(this);
- }
-
- // Selects the first node that matches the xpath expression
- public XmlNode SelectSingleNode(string xpath)
- {
- XmlNodeList list = SelectNodes(xpath);
- // SelectNodes returns null for certain node types
- return list != null ? list[0] : null;
- }
-
- // Selects the first node that matches the xpath expression and given namespace context.
- public XmlNode SelectSingleNode(string xpath, XmlNamespaceManager nsmgr)
- {
- XPathNavigator xn = (this).CreateNavigator();
- //if the method is called on node types like DocType, Entity, XmlDeclaration,
- //the navigator returned is null. So just return null from here for those node types.
- if (xn == null)
- return null;
- XPathExpression exp = xn.Compile(xpath);
- exp.SetContext(nsmgr);
- return new XPathNodeList(xn.Select(exp))[0];
- }
-
- // Selects all nodes that match the xpath expression
- public XmlNodeList SelectNodes(string xpath)
- {
- XPathNavigator n = (this).CreateNavigator();
- //if the method is called on node types like DocType, Entity, XmlDeclaration,
- //the navigator returned is null. So just return null from here for those node types.
- if (n == null)
- return null;
- return new XPathNodeList(n.Select(xpath));
- }
-
- // Selects all nodes that match the xpath expression and given namespace context.
- public XmlNodeList SelectNodes(string xpath, XmlNamespaceManager nsmgr)
- {
- XPathNavigator xn = (this).CreateNavigator();
- //if the method is called on node types like DocType, Entity, XmlDeclaration,
- //the navigator returned is null. So just return null from here for those node types.
- if (xn == null)
- return null;
- XPathExpression exp = xn.Compile(xpath);
- exp.SetContext(nsmgr);
- return new XPathNodeList(xn.Select(exp));
- }
-
- // Gets the name of the node.
- public abstract string Name
- {
- get;
- }
-
- // Gets or sets the value of the node.
- public virtual string Value
- {
- get { return null; }
- set { throw new InvalidOperationException(string.Format(ResXml.Xdom_Node_SetVal, NodeType)); }
- }
-
- // Gets the type of the current node.
- public abstract XmlNodeType NodeType
- {
- get;
- }
-
- // Gets the parent of this node (for nodes that can have parents).
- public virtual XmlNode ParentNode
- {
- get
- {
- Debug.Assert(parentNode != null);
-
- if (parentNode.NodeType != XmlNodeType.Document)
- {
- return parentNode;
- }
-
- // Linear lookup through the children of the document
- XmlLinkedNode firstChild = parentNode.FirstChild as XmlLinkedNode;
- if (firstChild != null)
- {
- XmlLinkedNode node = firstChild;
- do
- {
- if (node == this)
- {
- return parentNode;
- }
- node = node.next;
- }
- while (node != null
- && node != firstChild);
- }
- return null;
- }
- }
-
- // Gets all children of this node.
- public virtual XmlNodeList ChildNodes
- {
- get { return new XmlChildNodes(this); }
- }
-
- // Gets the node immediately preceding this node.
- public virtual XmlNode PreviousSibling
- {
- get { return null; }
- }
-
- // Gets the node immediately following this node.
- public virtual XmlNode NextSibling
- {
- get { return null; }
- }
-
- // Gets a XmlAttributeCollection containing the attributes
- // of this node.
- public virtual XmlAttributeCollection Attributes
- {
- get { return null; }
- }
-
- // Gets the XmlDocument that contains this node.
- public virtual XmlDocument OwnerDocument
- {
- get
- {
- Debug.Assert(parentNode != null);
- if (parentNode.NodeType == XmlNodeType.Document)
- return (XmlDocument)parentNode;
- return parentNode.OwnerDocument;
- }
- }
-
- // Gets the first child of this node.
- public virtual XmlNode FirstChild
- {
- get
- {
- XmlLinkedNode linkedNode = LastNode;
- if (linkedNode != null)
- return linkedNode.next;
-
- return null;
- }
- }
-
- // Gets the last child of this node.
- public virtual XmlNode LastChild
- {
- get { return LastNode; }
- }
-
- internal virtual bool IsContainer
- {
- get { return false; }
- }
-
- internal virtual XmlLinkedNode LastNode
- {
- get { return null; }
- set { }
- }
-
- internal bool AncestorNode(XmlNode node)
- {
- XmlNode n = this.ParentNode;
-
- while (n != null && n != this)
- {
- if (n == node)
- return true;
- n = n.ParentNode;
- }
-
- return false;
- }
-
- //trace to the top to find out its parent node.
- internal bool IsConnected()
- {
- XmlNode parent = ParentNode;
- while (parent != null && !(parent.NodeType == XmlNodeType.Document))
- parent = parent.ParentNode;
- return parent != null;
- }
-
- // Inserts the specified node immediately before the specified reference node.
- public virtual XmlNode InsertBefore(XmlNode newChild, XmlNode refChild)
- {
- if (this == newChild || AncestorNode(newChild))
- throw new ArgumentException(ResXml.Xdom_Node_Insert_Child);
-
- if (refChild == null)
- return AppendChild(newChild);
-
- if (!IsContainer)
- throw new InvalidOperationException(ResXml.Xdom_Node_Insert_Contain);
-
- if (refChild.ParentNode != this)
- throw new ArgumentException(ResXml.Xdom_Node_Insert_Path);
-
- if (newChild == refChild)
- return newChild;
-
- XmlDocument childDoc = newChild.OwnerDocument;
- XmlDocument thisDoc = OwnerDocument;
- if (childDoc != null && childDoc != thisDoc && childDoc != this)
- throw new ArgumentException(ResXml.Xdom_Node_Insert_Context);
-
- if (!CanInsertBefore(newChild, refChild))
- throw new InvalidOperationException(ResXml.Xdom_Node_Insert_Location);
-
- if (newChild.ParentNode != null)
- newChild.ParentNode.RemoveChild(newChild);
-
- // special case for doc-fragment.
- if (newChild.NodeType == XmlNodeType.DocumentFragment)
- {
- XmlNode first = newChild.FirstChild;
- XmlNode node = first;
- if (node != null)
- {
- newChild.RemoveChild(node);
- InsertBefore(node, refChild);
- // insert the rest of the children after this one.
- InsertAfter(newChild, node);
- }
- return first;
- }
-
- if (!(newChild is XmlLinkedNode) || !IsValidChildType(newChild.NodeType))
- throw new InvalidOperationException(ResXml.Xdom_Node_Insert_TypeConflict);
-
- XmlLinkedNode newNode = (XmlLinkedNode)newChild;
- XmlLinkedNode refNode = (XmlLinkedNode)refChild;
-
- string newChildValue = newChild.Value;
- XmlNodeChangedEventArgs args = GetEventArgs(newChild, newChild.ParentNode, this, newChildValue, newChildValue, XmlNodeChangedAction.Insert);
-
- if (args != null)
- BeforeEvent(args);
-
- if (refNode == FirstChild)
- {
- newNode.next = refNode;
- LastNode.next = newNode;
- newNode.SetParent(this);
-
- if (newNode.IsText)
- {
- if (refNode.IsText)
- {
- NestTextNodes(newNode, refNode);
- }
- }
- }
- else
- {
- XmlLinkedNode prevNode = (XmlLinkedNode)refNode.PreviousSibling;
-
- newNode.next = refNode;
- prevNode.next = newNode;
- newNode.SetParent(this);
-
- if (prevNode.IsText)
- {
- if (newNode.IsText)
- {
- NestTextNodes(prevNode, newNode);
- if (refNode.IsText)
- {
- NestTextNodes(newNode, refNode);
- }
- }
- else
- {
- if (refNode.IsText)
- {
- UnnestTextNodes(prevNode, refNode);
- }
- }
- }
- else
- {
- if (newNode.IsText)
- {
- if (refNode.IsText)
- {
- NestTextNodes(newNode, refNode);
- }
- }
- }
- }
-
- if (args != null)
- AfterEvent(args);
-
- return newNode;
- }
-
- // Inserts the specified node immediately after the specified reference node.
- public virtual XmlNode InsertAfter(XmlNode newChild, XmlNode refChild)
- {
- if (this == newChild || AncestorNode(newChild))
- throw new ArgumentException(ResXml.Xdom_Node_Insert_Child);
-
- if (refChild == null)
- return PrependChild(newChild);
-
- if (!IsContainer)
- throw new InvalidOperationException(ResXml.Xdom_Node_Insert_Contain);
-
- if (refChild.ParentNode != this)
- throw new ArgumentException(ResXml.Xdom_Node_Insert_Path);
-
- if (newChild == refChild)
- return newChild;
-
- XmlDocument childDoc = newChild.OwnerDocument;
- XmlDocument thisDoc = OwnerDocument;
- if (childDoc != null && childDoc != thisDoc && childDoc != this)
- throw new ArgumentException(ResXml.Xdom_Node_Insert_Context);
-
- if (!CanInsertAfter(newChild, refChild))
- throw new InvalidOperationException(ResXml.Xdom_Node_Insert_Location);
-
- if (newChild.ParentNode != null)
- newChild.ParentNode.RemoveChild(newChild);
-
- // special case for doc-fragment.
- if (newChild.NodeType == XmlNodeType.DocumentFragment)
- {
- XmlNode last = refChild;
- XmlNode first = newChild.FirstChild;
- XmlNode node = first;
- while (node != null)
- {
- XmlNode next = node.NextSibling;
- newChild.RemoveChild(node);
- InsertAfter(node, last);
- last = node;
- node = next;
- }
- return first;
- }
-
- if (!(newChild is XmlLinkedNode) || !IsValidChildType(newChild.NodeType))
- throw new InvalidOperationException(ResXml.Xdom_Node_Insert_TypeConflict);
-
- XmlLinkedNode newNode = (XmlLinkedNode)newChild;
- XmlLinkedNode refNode = (XmlLinkedNode)refChild;
-
- string newChildValue = newChild.Value;
- XmlNodeChangedEventArgs args = GetEventArgs(newChild, newChild.ParentNode, this, newChildValue, newChildValue, XmlNodeChangedAction.Insert);
-
- if (args != null)
- BeforeEvent(args);
-
- if (refNode == LastNode)
- {
- newNode.next = refNode.next;
- refNode.next = newNode;
- LastNode = newNode;
- newNode.SetParent(this);
-
- if (refNode.IsText)
- {
- if (newNode.IsText)
- {
- NestTextNodes(refNode, newNode);
- }
- }
- }
- else
- {
- XmlLinkedNode nextNode = refNode.next;
-
- newNode.next = nextNode;
- refNode.next = newNode;
- newNode.SetParent(this);
-
- if (refNode.IsText)
- {
- if (newNode.IsText)
- {
- NestTextNodes(refNode, newNode);
- if (nextNode.IsText)
- {
- NestTextNodes(newNode, nextNode);
- }
- }
- else
- {
- if (nextNode.IsText)
- {
- UnnestTextNodes(refNode, nextNode);
- }
- }
- }
- else
- {
- if (newNode.IsText)
- {
- if (nextNode.IsText)
- {
- NestTextNodes(newNode, nextNode);
- }
- }
- }
- }
-
-
- if (args != null)
- AfterEvent(args);
-
- return newNode;
- }
-
- // Replaces the child node oldChild with newChild node.
- public virtual XmlNode ReplaceChild(XmlNode newChild, XmlNode oldChild)
- {
- XmlNode nextNode = oldChild.NextSibling;
- RemoveChild(oldChild);
- XmlNode node = InsertBefore(newChild, nextNode);
- return oldChild;
- }
-
- // Removes specified child node.
- public virtual XmlNode RemoveChild(XmlNode oldChild)
- {
- if (!IsContainer)
- throw new InvalidOperationException(ResXml.Xdom_Node_Remove_Contain);
-
- if (oldChild.ParentNode != this)
- throw new ArgumentException(ResXml.Xdom_Node_Remove_Child);
-
- XmlLinkedNode oldNode = (XmlLinkedNode)oldChild;
-
- string oldNodeValue = oldNode.Value;
- XmlNodeChangedEventArgs args = GetEventArgs(oldNode, this, null, oldNodeValue, oldNodeValue, XmlNodeChangedAction.Remove);
-
- if (args != null)
- BeforeEvent(args);
-
- XmlLinkedNode lastNode = LastNode;
-
- if (oldNode == FirstChild)
- {
- if (oldNode == lastNode)
- {
- LastNode = null;
- oldNode.next = null;
- oldNode.SetParent(null);
- }
- else
- {
- XmlLinkedNode nextNode = oldNode.next;
-
- if (nextNode.IsText)
- {
- if (oldNode.IsText)
- {
- UnnestTextNodes(oldNode, nextNode);
- }
- }
-
- lastNode.next = nextNode;
- oldNode.next = null;
- oldNode.SetParent(null);
- }
- }
- else
- {
- if (oldNode == lastNode)
- {
- XmlLinkedNode prevNode = (XmlLinkedNode)oldNode.PreviousSibling;
- prevNode.next = oldNode.next;
- LastNode = prevNode;
- oldNode.next = null;
- oldNode.SetParent(null);
- }
- else
- {
- XmlLinkedNode prevNode = (XmlLinkedNode)oldNode.PreviousSibling;
- XmlLinkedNode nextNode = oldNode.next;
-
- if (nextNode.IsText)
- {
- if (prevNode.IsText)
- {
- NestTextNodes(prevNode, nextNode);
- }
- else
- {
- if (oldNode.IsText)
- {
- UnnestTextNodes(oldNode, nextNode);
- }
- }
- }
-
- prevNode.next = nextNode;
- oldNode.next = null;
- oldNode.SetParent(null);
- }
- }
-
- if (args != null)
- AfterEvent(args);
-
- return oldChild;
- }
-
- // Adds the specified node to the beginning of the list of children of this node.
- public virtual XmlNode PrependChild(XmlNode newChild)
- {
- return InsertBefore(newChild, FirstChild);
- }
-
- // Adds the specified node to the end of the list of children of this node.
- public virtual XmlNode AppendChild(XmlNode newChild)
- {
- XmlDocument thisDoc = OwnerDocument;
- if (thisDoc == null)
- {
- thisDoc = this as XmlDocument;
- }
- if (!IsContainer)
- throw new InvalidOperationException(ResXml.Xdom_Node_Insert_Contain);
-
- if (this == newChild || AncestorNode(newChild))
- throw new ArgumentException(ResXml.Xdom_Node_Insert_Child);
-
- if (newChild.ParentNode != null)
- newChild.ParentNode.RemoveChild(newChild);
-
- XmlDocument childDoc = newChild.OwnerDocument;
- if (childDoc != null && childDoc != thisDoc && childDoc != this)
- throw new ArgumentException(ResXml.Xdom_Node_Insert_Context);
-
- // special case for doc-fragment.
- if (newChild.NodeType == XmlNodeType.DocumentFragment)
- {
- XmlNode first = newChild.FirstChild;
- XmlNode node = first;
- while (node != null)
- {
- XmlNode next = node.NextSibling;
- newChild.RemoveChild(node);
- AppendChild(node);
- node = next;
- }
- return first;
- }
-
- if (!(newChild is XmlLinkedNode) || !IsValidChildType(newChild.NodeType))
- throw new InvalidOperationException(ResXml.Xdom_Node_Insert_TypeConflict);
-
-
- if (!CanInsertAfter(newChild, LastChild))
- throw new InvalidOperationException(ResXml.Xdom_Node_Insert_Location);
-
- string newChildValue = newChild.Value;
- XmlNodeChangedEventArgs args = GetEventArgs(newChild, newChild.ParentNode, this, newChildValue, newChildValue, XmlNodeChangedAction.Insert);
-
- if (args != null)
- BeforeEvent(args);
-
- XmlLinkedNode refNode = LastNode;
- XmlLinkedNode newNode = (XmlLinkedNode)newChild;
-
- if (refNode == null)
- {
- newNode.next = newNode;
- LastNode = newNode;
- newNode.SetParent(this);
- }
- else
- {
- newNode.next = refNode.next;
- refNode.next = newNode;
- LastNode = newNode;
- newNode.SetParent(this);
-
- if (refNode.IsText)
- {
- if (newNode.IsText)
- {
- NestTextNodes(refNode, newNode);
- }
- }
- }
-
- if (args != null)
- AfterEvent(args);
-
- return newNode;
- }
-
- //the function is provided only at Load time to speed up Load process
- internal virtual XmlNode AppendChildForLoad(XmlNode newChild, XmlDocument doc)
- {
- XmlNodeChangedEventArgs args = doc.GetInsertEventArgsForLoad(newChild, this);
-
- if (args != null)
- doc.BeforeEvent(args);
-
- XmlLinkedNode refNode = LastNode;
- XmlLinkedNode newNode = (XmlLinkedNode)newChild;
-
- if (refNode == null)
- {
- newNode.next = newNode;
- LastNode = newNode;
- newNode.SetParentForLoad(this);
- }
- else
- {
- newNode.next = refNode.next;
- refNode.next = newNode;
- LastNode = newNode;
- if (refNode.IsText
- && newNode.IsText)
- {
- NestTextNodes(refNode, newNode);
- }
- else
- {
- newNode.SetParentForLoad(this);
- }
- }
-
- if (args != null)
- doc.AfterEvent(args);
-
- return newNode;
- }
-
- internal virtual bool IsValidChildType(XmlNodeType type)
- {
- return false;
- }
-
- internal virtual bool CanInsertBefore(XmlNode newChild, XmlNode refChild)
- {
- return true;
- }
-
- internal virtual bool CanInsertAfter(XmlNode newChild, XmlNode refChild)
- {
- return true;
- }
-
- // Gets a value indicating whether this node has any child nodes.
- public virtual bool HasChildNodes
- {
- get { return LastNode != null; }
- }
-
- // Creates a duplicate of this node.
- public abstract XmlNode CloneNode(bool deep);
-
- internal virtual void CopyChildren(XmlDocument doc, XmlNode container, bool deep)
- {
- for (XmlNode child = container.FirstChild; child != null; child = child.NextSibling)
- {
- AppendChildForLoad(child.CloneNode(deep), doc);
- }
- }
-
- // DOM Level 2
-
- // Puts all XmlText nodes in the full depth of the sub-tree
- // underneath this XmlNode into a "normal" form where only
- // markup (e.g., tags, comments, processing instructions, CDATA sections,
- // and entity references) separates XmlText nodes, that is, there
- // are no adjacent XmlText nodes.
- public virtual void Normalize()
- {
- XmlNode firstChildTextLikeNode = null;
- StringBuilder sb = new StringBuilder();
- for (XmlNode crtChild = this.FirstChild; crtChild != null;)
- {
- XmlNode nextChild = crtChild.NextSibling;
- switch (crtChild.NodeType)
- {
- case XmlNodeType.Text:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- {
- sb.Append(crtChild.Value);
- XmlNode winner = NormalizeWinner(firstChildTextLikeNode, crtChild);
- if (winner == firstChildTextLikeNode)
- {
- this.RemoveChild(crtChild);
- }
- else
- {
- if (firstChildTextLikeNode != null)
- this.RemoveChild(firstChildTextLikeNode);
- firstChildTextLikeNode = crtChild;
- }
- break;
- }
- case XmlNodeType.Element:
- {
- crtChild.Normalize();
- goto default;
- }
- default:
- {
- if (firstChildTextLikeNode != null)
- {
- firstChildTextLikeNode.Value = sb.ToString();
- firstChildTextLikeNode = null;
- }
- sb.Remove(0, sb.Length);
- break;
- }
- }
- crtChild = nextChild;
- }
- if (firstChildTextLikeNode != null && sb.Length > 0)
- firstChildTextLikeNode.Value = sb.ToString();
- }
-
- private XmlNode NormalizeWinner(XmlNode firstNode, XmlNode secondNode)
- {
- //first node has the priority
- if (firstNode == null)
- return secondNode;
- Debug.Assert(firstNode.NodeType == XmlNodeType.Text
- || firstNode.NodeType == XmlNodeType.SignificantWhitespace
- || firstNode.NodeType == XmlNodeType.Whitespace
- || secondNode.NodeType == XmlNodeType.Text
- || secondNode.NodeType == XmlNodeType.SignificantWhitespace
- || secondNode.NodeType == XmlNodeType.Whitespace);
- if (firstNode.NodeType == XmlNodeType.Text)
- return firstNode;
- if (secondNode.NodeType == XmlNodeType.Text)
- return secondNode;
- if (firstNode.NodeType == XmlNodeType.SignificantWhitespace)
- return firstNode;
- if (secondNode.NodeType == XmlNodeType.SignificantWhitespace)
- return secondNode;
- if (firstNode.NodeType == XmlNodeType.Whitespace)
- return firstNode;
- if (secondNode.NodeType == XmlNodeType.Whitespace)
- return secondNode;
- Debug.Assert(true, "shouldn't have fall through here.");
- return null;
- }
-
- // Test if the DOM implementation implements a specific feature.
- public virtual bool Supports(string feature, string version)
- {
- if (String.Compare("XML", feature, StringComparison.OrdinalIgnoreCase) == 0)
- {
- if (version == null || version == "1.0" || version == "2.0")
- return true;
- }
- return false;
- }
-
- // Gets the namespace URI of this node.
- public virtual string NamespaceURI
- {
- get { return string.Empty; }
- }
-
- // Gets or sets the namespace prefix of this node.
- public virtual string Prefix
- {
- get { return string.Empty; }
- set { }
- }
-
- // Gets the name of the node without the namespace prefix.
- public abstract string LocalName
- {
- get;
- }
-
- // Microsoft extensions
-
- // Gets a value indicating whether the node is read-only.
- public virtual bool IsReadOnly
- {
- get
- {
- XmlDocument doc = OwnerDocument;
- return HasReadOnlyParent(this);
- }
- }
-
- internal static bool HasReadOnlyParent(XmlNode n)
- {
- while (n != null)
- {
- switch (n.NodeType)
- {
- case XmlNodeType.EntityReference:
- case XmlNodeType.Entity:
- return true;
-
- case XmlNodeType.Attribute:
- n = ((XmlAttribute)n).OwnerElement;
- break;
-
- default:
- n = n.ParentNode;
- break;
- }
- }
- return false;
- }
-
- // Creates a duplicate of this node.
- public virtual XmlNode Clone()
- {
- return this.CloneNode(true);
- }
-
- object ICloneable.Clone()
- {
- return this.CloneNode(true);
- }
-
- // Provides a simple ForEach-style iteration over the
- // collection of nodes in this XmlNamedNodeMap.
- IEnumerator IEnumerable.GetEnumerator()
- {
- return new XmlChildEnumerator(this);
- }
-
- public IEnumerator GetEnumerator()
- {
- return new XmlChildEnumerator(this);
- }
-
- private void AppendChildText(StringBuilder builder)
- {
- for (XmlNode child = FirstChild; child != null; child = child.NextSibling)
- {
- if (child.FirstChild == null)
- {
- if (child.NodeType == XmlNodeType.Text || child.NodeType == XmlNodeType.CDATA
- || child.NodeType == XmlNodeType.Whitespace || child.NodeType == XmlNodeType.SignificantWhitespace)
- builder.Append(child.InnerText);
- }
- else
- {
- child.AppendChildText(builder);
- }
- }
- }
-
- // Gets or sets the concatenated values of the node and
- // all its children.
- public virtual string InnerText
- {
- get
- {
- XmlNode fc = FirstChild;
- if (fc == null)
- {
- return string.Empty;
- }
- if (fc.NextSibling == null)
- {
- XmlNodeType nodeType = fc.NodeType;
- switch (nodeType)
- {
- case XmlNodeType.Text:
- case XmlNodeType.CDATA:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- return fc.Value;
- }
- }
- StringBuilder builder = new StringBuilder();
- AppendChildText(builder);
- return builder.ToString();
- }
-
- set
- {
- XmlNode firstChild = FirstChild;
- if (firstChild != null //there is one child
- && firstChild.NextSibling == null // and exactly one
- && firstChild.NodeType == XmlNodeType.Text)//which is a text node
- {
- //this branch is for perf reason and event fired when TextNode.Value is changed
- firstChild.Value = value;
- }
- else
- {
- RemoveAll();
- AppendChild(OwnerDocument.CreateTextNode(value));
- }
- }
- }
-
- // Gets the markup representing this node and all its children.
- public virtual string OuterXml
- {
- get
- {
- StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
- XmlDOMTextWriter xw = new XmlDOMTextWriter(sw);
- try
- {
- WriteTo(xw);
- }
- finally
- {
- xw.Close();
- }
- return sw.ToString();
- }
- }
-
- // Gets or sets the markup representing just the children of this node.
- public virtual string InnerXml
- {
- get
- {
- StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
- XmlDOMTextWriter xw = new XmlDOMTextWriter(sw);
- try
- {
- WriteContentTo(xw);
- }
- finally
- {
- xw.Close();
- }
- return sw.ToString();
- }
-
- set
- {
- throw new InvalidOperationException(ResXml.Xdom_Set_InnerXml);
- }
- }
-
- public virtual IXmlSchemaInfo SchemaInfo
- {
- get
- {
- return XmlDocument.NotKnownSchemaInfo;
- }
- }
-
- public virtual String BaseURI
- {
- get
- {
- XmlNode curNode = this.ParentNode; //save one while loop since if going to here, the nodetype of this node can't be document, entity and entityref
- while (curNode != null)
- {
- XmlNodeType nt = curNode.NodeType;
- //EntityReference's children come from the dtd where they are defined.
- //we need to investigate the same thing for entity's children if they are defined in an external dtd file.
- if (nt == XmlNodeType.EntityReference)
- return ((XmlEntityReference)curNode).ChildBaseURI;
- if (nt == XmlNodeType.Document
- || nt == XmlNodeType.Entity
- || nt == XmlNodeType.Attribute)
- return curNode.BaseURI;
- curNode = curNode.ParentNode;
- }
- return String.Empty;
- }
- }
-
- // Saves the current node to the specified XmlWriter.
- public abstract void WriteTo(XmlWriter w);
-
- // Saves all the children of the node to the specified XmlWriter.
- public abstract void WriteContentTo(XmlWriter w);
-
- // Removes all the children and/or attributes
- // of the current node.
- public virtual void RemoveAll()
- {
- XmlNode child = FirstChild;
- XmlNode sibling = null;
-
- while (child != null)
- {
- sibling = child.NextSibling;
- RemoveChild(child);
- child = sibling;
- }
- }
-
- internal XmlDocument Document
- {
- get
- {
- if (NodeType == XmlNodeType.Document)
- return (XmlDocument)this;
- return OwnerDocument;
- }
- }
-
- // Looks up the closest xmlns declaration for the given
- // prefix that is in scope for the current node and returns
- // the namespace URI in the declaration.
- public virtual string GetNamespaceOfPrefix(string prefix)
- {
- string namespaceName = GetNamespaceOfPrefixStrict(prefix);
- return namespaceName != null ? namespaceName : string.Empty;
- }
-
- internal string GetNamespaceOfPrefixStrict(string prefix)
- {
- XmlDocument doc = Document;
- if (doc != null)
- {
- prefix = doc.NameTable.Get(prefix);
- if (prefix == null)
- return null;
-
- XmlNode node = this;
- while (node != null)
- {
- if (node.NodeType == XmlNodeType.Element)
- {
- XmlElement elem = (XmlElement)node;
- if (elem.HasAttributes)
- {
- XmlAttributeCollection attrs = elem.Attributes;
- if (prefix.Length == 0)
- {
- for (int iAttr = 0; iAttr < attrs.Count; iAttr++)
- {
- XmlAttribute attr = attrs[iAttr];
- if (attr.Prefix.Length == 0)
- {
- if (Ref.Equal(attr.LocalName, doc.strXmlns))
- {
- return attr.Value; // found xmlns
- }
- }
- }
- }
- else
- {
- for (int iAttr = 0; iAttr < attrs.Count; iAttr++)
- {
- XmlAttribute attr = attrs[iAttr];
- if (Ref.Equal(attr.Prefix, doc.strXmlns))
- {
- if (Ref.Equal(attr.LocalName, prefix))
- {
- return attr.Value; // found xmlns:prefix
- }
- }
- else if (Ref.Equal(attr.Prefix, prefix))
- {
- return attr.NamespaceURI; // found prefix:attr
- }
- }
- }
- }
- if (Ref.Equal(node.Prefix, prefix))
- {
- return node.NamespaceURI;
- }
- node = node.ParentNode;
- }
- else if (node.NodeType == XmlNodeType.Attribute)
- {
- node = ((XmlAttribute)node).OwnerElement;
- }
- else
- {
- node = node.ParentNode;
- }
- }
- if (Ref.Equal(doc.strXml, prefix))
- { // xmlns:xml
- return doc.strReservedXml;
- }
- else if (Ref.Equal(doc.strXmlns, prefix))
- { // xmlns:xmlns
- return doc.strReservedXmlns;
- }
- }
- return null;
- }
-
- // Looks up the closest xmlns declaration for the given namespace
- // URI that is in scope for the current node and returns
- // the prefix defined in that declaration.
- public virtual string GetPrefixOfNamespace(string namespaceURI)
- {
- string prefix = GetPrefixOfNamespaceStrict(namespaceURI);
- return prefix != null ? prefix : string.Empty;
- }
-
- internal string GetPrefixOfNamespaceStrict(string namespaceURI)
- {
- XmlDocument doc = Document;
- if (doc != null)
- {
- namespaceURI = doc.NameTable.Add(namespaceURI);
-
- XmlNode node = this;
- while (node != null)
- {
- if (node.NodeType == XmlNodeType.Element)
- {
- XmlElement elem = (XmlElement)node;
- if (elem.HasAttributes)
- {
- XmlAttributeCollection attrs = elem.Attributes;
- for (int iAttr = 0; iAttr < attrs.Count; iAttr++)
- {
- XmlAttribute attr = attrs[iAttr];
- if (attr.Prefix.Length == 0)
- {
- if (Ref.Equal(attr.LocalName, doc.strXmlns))
- {
- if (attr.Value == namespaceURI)
- {
- return string.Empty; // found xmlns="namespaceURI"
- }
- }
- }
- else if (Ref.Equal(attr.Prefix, doc.strXmlns))
- {
- if (attr.Value == namespaceURI)
- {
- return attr.LocalName; // found xmlns:prefix="namespaceURI"
- }
- }
- else if (Ref.Equal(attr.NamespaceURI, namespaceURI))
- {
- return attr.Prefix; // found prefix:attr
- // with prefix bound to namespaceURI
- }
- }
- }
- if (Ref.Equal(node.NamespaceURI, namespaceURI))
- {
- return node.Prefix;
- }
- node = node.ParentNode;
- }
- else if (node.NodeType == XmlNodeType.Attribute)
- {
- node = ((XmlAttribute)node).OwnerElement;
- }
- else
- {
- node = node.ParentNode;
- }
- }
- if (Ref.Equal(doc.strReservedXml, namespaceURI))
- { // xmlns:xml
- return doc.strXml;
- }
- else if (Ref.Equal(doc.strReservedXmlns, namespaceURI))
- { // xmlns:xmlns
- return doc.strXmlns;
- }
- }
- return null;
- }
-
- // Retrieves the first child element with the specified name.
- public virtual XmlElement this[string name]
- {
- get
- {
- for (XmlNode n = FirstChild; n != null; n = n.NextSibling)
- {
- if (n.NodeType == XmlNodeType.Element && n.Name == name)
- return (XmlElement)n;
- }
- return null;
- }
- }
-
- // Retrieves the first child element with the specified LocalName and
- // NamespaceURI.
- public virtual XmlElement this[string localname, string ns]
- {
- get
- {
- for (XmlNode n = FirstChild; n != null; n = n.NextSibling)
- {
- if (n.NodeType == XmlNodeType.Element && n.LocalName == localname && n.NamespaceURI == ns)
- return (XmlElement)n;
- }
- return null;
- }
- }
-
- internal virtual void SetParent(XmlNode node)
- {
- if (node == null)
- {
- this.parentNode = OwnerDocument;
- }
- else
- {
- this.parentNode = node;
- }
- }
-
- internal virtual void SetParentForLoad(XmlNode node)
- {
- this.parentNode = node;
- }
-
- internal static void SplitName(string name, out string prefix, out string localName)
- {
- int colonPos = name.IndexOf(':'); // ordinal compare
- if (-1 == colonPos || 0 == colonPos || name.Length - 1 == colonPos)
- {
- prefix = string.Empty;
- localName = name;
- }
- else
- {
- prefix = name.Substring(0, colonPos);
- localName = name.Substring(colonPos + 1);
- }
- }
-
- internal virtual XmlNode FindChild(XmlNodeType type)
- {
- for (XmlNode child = FirstChild; child != null; child = child.NextSibling)
- {
- if (child.NodeType == type)
- {
- return child;
- }
- }
- return null;
- }
-
- internal virtual XmlNodeChangedEventArgs GetEventArgs(XmlNode node, XmlNode oldParent, XmlNode newParent, string oldValue, string newValue, XmlNodeChangedAction action)
- {
- XmlDocument doc = OwnerDocument;
- if (doc != null)
- {
- if (!doc.IsLoading)
- {
- if (((newParent != null && newParent.IsReadOnly) || (oldParent != null && oldParent.IsReadOnly)))
- throw new InvalidOperationException(ResXml.Xdom_Node_Modify_ReadOnly);
- }
- return doc.GetEventArgs(node, oldParent, newParent, oldValue, newValue, action);
- }
- return null;
- }
-
- internal virtual void BeforeEvent(XmlNodeChangedEventArgs args)
- {
- if (args != null)
- OwnerDocument.BeforeEvent(args);
- }
-
- internal virtual void AfterEvent(XmlNodeChangedEventArgs args)
- {
- if (args != null)
- OwnerDocument.AfterEvent(args);
- }
-
- internal virtual XmlSpace XmlSpace
- {
- get
- {
- XmlNode node = this;
- XmlElement elem = null;
- do
- {
- elem = node as XmlElement;
- if (elem != null && elem.HasAttribute("xml:space"))
- {
- switch (XmlConvert.TrimString(elem.GetAttribute("xml:space")))
- {
- case "default":
- return XmlSpace.Default;
- case "preserve":
- return XmlSpace.Preserve;
- default:
- //should we throw exception if value is otherwise?
- break;
- }
- }
- node = node.ParentNode;
- }
- while (node != null);
- return XmlSpace.None;
- }
- }
-
- internal virtual String XmlLang
- {
- get
- {
- XmlNode node = this;
- XmlElement elem = null;
- do
- {
- elem = node as XmlElement;
- if (elem != null)
- {
- if (elem.HasAttribute("xml:lang"))
- return elem.GetAttribute("xml:lang");
- }
- node = node.ParentNode;
- } while (node != null);
- return String.Empty;
- }
- }
-
- internal virtual XPathNodeType XPNodeType
- {
- get
- {
- return (XPathNodeType)(-1);
- }
- }
-
- internal virtual string XPLocalName
- {
- get
- {
- return string.Empty;
- }
- }
-
- internal virtual string GetXPAttribute(string localName, string namespaceURI)
- {
- return String.Empty;
- }
-
- internal virtual bool IsText
- {
- get
- {
- return false;
- }
- }
-
- public virtual XmlNode PreviousText
- {
- get
- {
- return null;
- }
- }
-
- internal static void NestTextNodes(XmlNode prevNode, XmlNode nextNode)
- {
- Debug.Assert(prevNode.IsText);
- Debug.Assert(nextNode.IsText);
-
- nextNode.parentNode = prevNode;
- }
-
- internal static void UnnestTextNodes(XmlNode prevNode, XmlNode nextNode)
- {
- Debug.Assert(prevNode.IsText);
- Debug.Assert(nextNode.IsText);
-
- nextNode.parentNode = prevNode.ParentNode;
- }
- private object debuggerDisplayProxy { get { return new DebuggerDisplayXmlNodeProxy(this); } }
- }
-
- [DebuggerDisplay("{ToString()}")]
- internal struct DebuggerDisplayXmlNodeProxy
- {
- private XmlNode _node;
-
- public DebuggerDisplayXmlNodeProxy(XmlNode node)
- {
- _node = node;
- }
-
- public override string ToString()
- {
- XmlNodeType nodeType = _node.NodeType;
- string result = nodeType.ToString();
- switch (nodeType)
- {
- case XmlNodeType.Element:
- case XmlNodeType.EntityReference:
- result += ", Name=\"" + _node.Name + "\"";
- break;
- case XmlNodeType.Attribute:
- case XmlNodeType.ProcessingInstruction:
- result += ", Name=\"" + _node.Name + "\", Value=\"" + XmlConvert.EscapeValueForDebuggerDisplay(_node.Value) + "\"";
- break;
- case XmlNodeType.Text:
- case XmlNodeType.CDATA:
- case XmlNodeType.Comment:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- case XmlNodeType.XmlDeclaration:
- result += ", Value=\"" + XmlConvert.EscapeValueForDebuggerDisplay(_node.Value) + "\"";
- break;
- case XmlNodeType.DocumentType:
- XmlDocumentType documentType = (XmlDocumentType)_node;
- result += ", Name=\"" + documentType.Name + "\", SYSTEM=\"" + documentType.SystemId + "\", PUBLIC=\"" + documentType.PublicId + "\", Value=\"" + XmlConvert.EscapeValueForDebuggerDisplay(documentType.InternalSubset) + "\"";
- break;
- default:
- break;
- }
- return result;
- }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeChangedEventArgs.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeChangedEventArgs.cs
deleted file mode 100644
index 486e8de375f..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeChangedEventArgs.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- public class XmlNodeChangedEventArgs : EventArgs
- {
- private XmlNodeChangedAction _action;
- private XmlNode _node;
- private XmlNode _oldParent;
- private XmlNode _newParent;
- private string _oldValue;
- private string _newValue;
-
- public XmlNodeChangedEventArgs(XmlNode node, XmlNode oldParent, XmlNode newParent, string oldValue, string newValue, XmlNodeChangedAction action)
- {
- _node = node;
- _oldParent = oldParent;
- _newParent = newParent;
- _action = action;
- _oldValue = oldValue;
- _newValue = newValue;
- }
-
- public XmlNodeChangedAction Action { get { return _action; } }
-
- public XmlNode Node { get { return _node; } }
-
- public XmlNode OldParent { get { return _oldParent; } }
-
- public XmlNode NewParent { get { return _newParent; } }
-
- public string OldValue { get { return _oldValue; } }
-
- public string NewValue { get { return _newValue; } }
- }
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeChangedEventHandler.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeChangedEventHandler.cs
deleted file mode 100644
index 24deb8446e0..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeChangedEventHandler.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- public delegate void XmlNodeChangedEventHandler(object sender, XmlNodeChangedEventArgs e);
-}
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeList.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeList.cs
deleted file mode 100644
index a4df002083f..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeList.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
-
- using System.Collections;
-
- // Represents an ordered collection of nodes.
- public abstract class XmlNodeList : IEnumerable, IDisposable
- {
- // Retrieves a node at the given index.
- public abstract XmlNode Item(int index);
-
- // Gets the number of nodes in this XmlNodeList.
- public abstract int Count { get; }
-
- // Provides a simple ForEach-style iteration over the collection of nodes in
- // this XmlNodeList.
- public abstract IEnumerator GetEnumerator();
-
- // Retrieves a node at the given index.
- [System.Runtime.CompilerServices.IndexerName("ItemOf")]
- public virtual XmlNode this[int i] { get { return Item(i); } }
-
- void IDisposable.Dispose()
- {
- PrivateDisposeNodeList();
- }
-
- protected virtual void PrivateDisposeNodeList() { }
- }
-}
-
diff --git a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeReader.cs b/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeReader.cs
deleted file mode 100644
index f74b4f0b320..00000000000
--- a/src/dotnet-svcutil/lib/src/FrameworkFork/Microsoft.Xml/Xml/Dom/XmlNodeReader.cs
+++ /dev/null
@@ -1,1952 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-namespace Microsoft.Xml
-{
- using System;
- using System.Text;
- using System.IO;
- using System.Diagnostics;
- using System.Collections;
- using System.Collections.Generic;
- using Microsoft.Xml.Schema;
- using System.Globalization;
-
- internal class XmlNodeReaderNavigator
- {
- private XmlNode _curNode;
- private XmlNode _elemNode;
- private XmlNode _logNode;
- private int _attrIndex;
- private int _logAttrIndex;
-
- //presave these 2 variables since they shouldn't change.
- private XmlNameTable _nameTable;
- private XmlDocument _doc;
-
- private int _nAttrInd; //used to identify virtual attributes of DocumentType node and XmlDeclaration node
-
- private const String strPublicID = "PUBLIC";
- private const String strSystemID = "SYSTEM";
- private const String strVersion = "version";
- private const String strStandalone = "standalone";
- private const String strEncoding = "encoding";
-
-
- //caching variables for perf reasons
- private int _nDeclarationAttrCount;
- private int _nDocTypeAttrCount;
-
- //variables for roll back the moves
- private int _nLogLevel;
- private int _nLogAttrInd;
- private bool _bLogOnAttrVal;
- private bool _bCreatedOnAttribute;
-
- internal struct VirtualAttribute
- {
- internal String name;
- internal String value;
-
- internal VirtualAttribute(String name, String value)
- {
- this.name = name;
- this.value = value;
- }
- };
-
- internal VirtualAttribute[] decNodeAttributes = {
- new VirtualAttribute( null, null ),
- new VirtualAttribute( null, null ),
- new VirtualAttribute( null, null )
- };
-
- internal VirtualAttribute[] docTypeNodeAttributes = {
- new VirtualAttribute( null, null ),
- new VirtualAttribute( null, null )
- };
-
- private bool _bOnAttrVal;
-
- public XmlNodeReaderNavigator(XmlNode node)
- {
- _curNode = node;
- _logNode = node;
- XmlNodeType nt = _curNode.NodeType;
- if (nt == XmlNodeType.Attribute)
- {
- _elemNode = null;
- _attrIndex = -1;
- _bCreatedOnAttribute = true;
- }
- else
- {
- _elemNode = node;
- _attrIndex = -1;
- _bCreatedOnAttribute = false;
- }
- //presave this for pref reason since it shouldn't change.
- if (nt == XmlNodeType.Document)
- _doc = (XmlDocument)_curNode;
- else
- _doc = node.OwnerDocument;
- _nameTable = _doc.NameTable;
- _nAttrInd = -1;
- //initialize the caching variables
- _nDeclarationAttrCount = -1;
- _nDocTypeAttrCount = -1;
- _bOnAttrVal = false;
- _bLogOnAttrVal = false;
- }
-
- public XmlNodeType NodeType
- {
- get
- {
- XmlNodeType nt = _curNode.NodeType;
- if (_nAttrInd != -1)
- {
- Debug.Assert(nt == XmlNodeType.XmlDeclaration || nt == XmlNodeType.DocumentType);
- if (_bOnAttrVal)
- return XmlNodeType.Text;
- else
- return XmlNodeType.Attribute;
- }
- return nt;
- }
- }
-
- public String NamespaceURI
- {
- get { return _curNode.NamespaceURI; }
- }
-
- public String Name
- {
- get
- {
- if (_nAttrInd != -1)
- {
- Debug.Assert(_curNode.NodeType == XmlNodeType.XmlDeclaration || _curNode.NodeType == XmlNodeType.DocumentType);
- if (_bOnAttrVal)
- return String.Empty; //Text node's name is String.Empty
- else
- {
- Debug.Assert(_nAttrInd >= 0 && _nAttrInd < AttributeCount);
- if (_curNode.NodeType == XmlNodeType.XmlDeclaration)
- return decNodeAttributes[_nAttrInd].name;
- else
- return docTypeNodeAttributes[_nAttrInd].name;
- }
- }
- if (IsLocalNameEmpty(_curNode.NodeType))
- return String.Empty;
- return _curNode.Name;
- }
- }
-
- public String LocalName
- {
- get
- {
- if (_nAttrInd != -1)
- //for the nodes in this case, their LocalName should be the same as their name
- return Name;
- if (IsLocalNameEmpty(_curNode.NodeType))
- return String.Empty;
- return _curNode.LocalName;
- }
- }
-
- internal bool IsOnAttrVal
- {
- get
- {
- return _bOnAttrVal;
- }
- }
-
- internal XmlNode OwnerElementNode
- {
- get
- {
- if (_bCreatedOnAttribute)
- return null;
- return _elemNode;
- }
- }
-
- internal bool CreatedOnAttribute
- {
- get
- {
- return _bCreatedOnAttribute;
- }
- }
-
- private bool IsLocalNameEmpty(XmlNodeType nt)
- {
- switch (nt)
- {
- case XmlNodeType.None:
- case XmlNodeType.Text:
- case XmlNodeType.CDATA:
- case XmlNodeType.Comment:
- case XmlNodeType.Document:
- case XmlNodeType.DocumentFragment:
- case XmlNodeType.Whitespace:
- case XmlNodeType.SignificantWhitespace:
- case XmlNodeType.EndElement:
- case XmlNodeType.EndEntity:
- return true;
- case XmlNodeType.Element:
- case XmlNodeType.Attribute:
- case XmlNodeType.EntityReference:
- case XmlNodeType.Entity:
- case XmlNodeType.ProcessingInstruction:
- case XmlNodeType.DocumentType:
- case XmlNodeType.Notation:
- case XmlNodeType.XmlDeclaration:
- return false;
- default:
- return true;
- }
- }
-
- public String Prefix
- {
- get { return _curNode.Prefix; }
- }
-
- public bool HasValue
- {
- //In DOM, DocumentType node and XmlDeclaration node doesn't value
- //In XPathNavigator, XmlDeclaration node's value is its InnerText; DocumentType doesn't have value
- //In XmlReader, DocumentType node's value is its InternalSubset which is never null ( at least String.Empty )
- get
- {
- if (_nAttrInd != -1)
- {
- //Pointing at the one of virtual attributes of Declaration or DocumentType nodes
- Debug.Assert(_curNode.NodeType == XmlNodeType.XmlDeclaration || _curNode.NodeType == XmlNodeType.DocumentType);
- Debug.Assert(_nAttrInd >= 0 && _nAttrInd < AttributeCount);
- return true;
- }
- if (_curNode.Value != null || _curNode.NodeType == XmlNodeType.DocumentType)
- return true;
- return false;
- }
- }
-
- public String Value
- {
- //See comments in HasValue
- get
- {
- String retValue = null;
- XmlNodeType nt = _curNode.NodeType;
- if (_nAttrInd != -1)
- {
- //Pointing at the one of virtual attributes of Declaration or DocumentType nodes
- Debug.Assert(nt == XmlNodeType.XmlDeclaration || nt == XmlNodeType.DocumentType);
- Debug.Assert(_nAttrInd >= 0 && _nAttrInd < AttributeCount);
- if (_curNode.NodeType == XmlNodeType.XmlDeclaration)
- return decNodeAttributes[_nAttrInd].value;
- else
- return docTypeNodeAttributes[_nAttrInd].value;
- }
- if (nt == XmlNodeType.DocumentType)
- retValue = ((XmlDocumentType)_curNode).InternalSubset; //in this case nav.Value will be null
- else if (nt == XmlNodeType.XmlDeclaration)
- {
- StringBuilder strb = new StringBuilder(String.Empty);
- if (_nDeclarationAttrCount == -1)
- InitDecAttr();
- for (int i = 0; i < _nDeclarationAttrCount; i++)
- {
- strb.Append(decNodeAttributes[i].name + "=\"" + decNodeAttributes[i].value + "\"");
- if (i != (_nDeclarationAttrCount - 1))
- strb.Append(" ");
- }
- retValue = strb.ToString();
- }
- else
- retValue = _curNode.Value;
- return (retValue == null) ? String.Empty : retValue;
- }
- }
-
- public String BaseURI
- {
- get { return _curNode.BaseURI; }
- }
-
- public XmlSpace XmlSpace
- {
- get { return _curNode.XmlSpace; }
- }
-
- public String XmlLang
- {
- get { return _curNode.XmlLang; }
- }
-
- public bool IsEmptyElement
- {
- get
- {
- if (_curNode.NodeType == XmlNodeType.Element)
- {
- return ((XmlElement)_curNode).IsEmpty;
- }
- return false;
- }
- }
-
- public bool IsDefault
- {
- get
- {
- if (_curNode.NodeType == XmlNodeType.Attribute)
- {
- return !((XmlAttribute)_curNode).Specified;
- }
- return false;
- }
- }
-
- public IXmlSchemaInfo SchemaInfo
- {
- get
- {
- return _curNode.SchemaInfo;
- }
- }
-
- public XmlNameTable NameTable
- {
- get { return _nameTable; }
- }
-
- public int AttributeCount
- {
- get
- {
- if (_bCreatedOnAttribute)
- return 0;
- XmlNodeType nt = _curNode.NodeType;
- if (nt == XmlNodeType.Element)
- return ((XmlElement)_curNode).Attributes.Count;
- else if (nt == XmlNodeType.Attribute
- || (_bOnAttrVal && nt != XmlNodeType.XmlDeclaration && nt != XmlNodeType.DocumentType))
- return _elemNode.Attributes.Count;
- else if (nt == XmlNodeType.XmlDeclaration)
- {
- if (_nDeclarationAttrCount != -1)
- return _nDeclarationAttrCount;
- InitDecAttr();
- return _nDeclarationAttrCount;
- }
- else if (nt == XmlNodeType.DocumentType)
- {
- if (_nDocTypeAttrCount != -1)
- return _nDocTypeAttrCount;
- InitDocTypeAttr();
- return _nDocTypeAttrCount;
- }
- return 0;
- }
- }
-
- private void CheckIndexCondition(int attributeIndex)
- {
- if (attributeIndex < 0 || attributeIndex >= AttributeCount)
- {
- throw new ArgumentOutOfRangeException("attributeIndex");
- }
- }
-
- //8 functions below are the helper functions to deal with virtual attributes of XmlDeclaration nodes and DocumentType nodes.
- private void InitDecAttr()
- {
- int i = 0;
- String strTemp = _doc.Version;
- if (strTemp != null && strTemp.Length != 0)
- {
- decNodeAttributes[i].name = strVersion;
- decNodeAttributes[i].value = strTemp;
- i++;
- }
- strTemp = _doc.Encoding;
- if (strTemp != null && strTemp.Length != 0)
- {
- decNodeAttributes[i].name = strEncoding;
- decNodeAttributes[i].value = strTemp;
- i++;
- }
- strTemp = _doc.Standalone;
- if (strTemp != null && strTemp.Length != 0)
- {
- decNodeAttributes[i].name = strStandalone;
- decNodeAttributes[i].value = strTemp;
- i++;
- }
- _nDeclarationAttrCount = i;
- }
-
- public String GetDeclarationAttr(XmlDeclaration decl, String name)
- {
- //PreCondition: curNode is pointing at Declaration node or one of its virtual attributes
- if (name == strVersion)
- return decl.Version;
- if (name == strEncoding)
- return decl.Encoding;
- if (name == strStandalone)
- return decl.Standalone;
- return null;
- }
-
- public String GetDeclarationAttr(int i)
- {
- if (_nDeclarationAttrCount == -1)
- InitDecAttr();
- return decNodeAttributes[i].value;
- }
-
- public int GetDecAttrInd(String name)
- {
- if (_nDeclarationAttrCount == -1)
- InitDecAttr();
- for (int i = 0; i < _nDeclarationAttrCount; i++)
- {
- if (decNodeAttributes[i].name == name)
- return i;
- }
- return -1;
- }
-
- private void InitDocTypeAttr()
- {
- int i = 0;
- XmlDocumentType docType = _doc.DocumentType;
- if (docType == null)
- {
- _nDocTypeAttrCount = 0;
- return;
- }
- String strTemp = docType.PublicId;
- if (strTemp != null)
- {
- docTypeNodeAttributes[i].name = strPublicID;
- docTypeNodeAttributes[i].value = strTemp;
- i++;
- }
- strTemp = docType.SystemId;
- if (strTemp != null)
- {
- docTypeNodeAttributes[i].name = strSystemID;
- docTypeNodeAttributes[i].value = strTemp;
- i++;
- }
- _nDocTypeAttrCount = i;
- }
-
- public String GetDocumentTypeAttr(XmlDocumentType docType, String name)
- {
- //PreCondition: nav is pointing at DocumentType node or one of its virtual attributes
- if (name == strPublicID)
- return docType.PublicId;
- if (name == strSystemID)
- return docType.SystemId;
- return null;
- }
-
- public String GetDocumentTypeAttr(int i)
- {
- if (_nDocTypeAttrCount == -1)
- InitDocTypeAttr();
- return docTypeNodeAttributes[i].value;
- }
-
- public int GetDocTypeAttrInd(String name)
- {
- if (_nDocTypeAttrCount == -1)
- InitDocTypeAttr();
- for (int i = 0; i < _nDocTypeAttrCount; i++)
- {
- if (docTypeNodeAttributes[i].name == name)
- return i;
- }
- return -1;
- }
-
- private String GetAttributeFromElement(XmlElement elem, String name)
- {
- XmlAttribute attr = elem.GetAttributeNode(name);
- if (attr != null)
- return attr.Value;
- return null;
- }
-
- public String GetAttribute(String name)
- {
- if (_bCreatedOnAttribute)
- return null;
- switch (_curNode.NodeType)
- {
- case XmlNodeType.Element:
- return GetAttributeFromElement((XmlElement)_curNode, name);
- case XmlNodeType.Attribute:
- return GetAttributeFromElement((XmlElement)_elemNode, name);
- case XmlNodeType.XmlDeclaration:
- return GetDeclarationAttr((XmlDeclaration)_curNode, name);
- case XmlNodeType.DocumentType:
- return GetDocumentTypeAttr((XmlDocumentType)_curNode, name);
- }
- return null;
- }
-
- private String GetAttributeFromElement(XmlElement elem, String name, String ns)
- {
- XmlAttribute attr = elem.GetAttributeNode(name, ns);
- if (attr != null)
- return attr.Value;
- return null;
- }
- public String GetAttribute(String name, String ns)
- {
- if (_bCreatedOnAttribute)
- return null;
- switch (_curNode.NodeType)
- {
- case XmlNodeType.Element:
- return GetAttributeFromElement((XmlElement)_curNode, name, ns);
- case XmlNodeType.Attribute:
- return GetAttributeFromElement((XmlElement)_elemNode, name, ns);
- case XmlNodeType.XmlDeclaration:
- return (ns.Length == 0) ? GetDeclarationAttr((XmlDeclaration)_curNode, name) : null;
- case XmlNodeType.DocumentType:
- return (ns.Length == 0) ? GetDocumentTypeAttr((XmlDocumentType)_curNode, name) : null;
- }
- return null;
- }
-
- public String GetAttribute(int attributeIndex)
- {
- if (_bCreatedOnAttribute)
- return null;
- switch (_curNode.NodeType)
- {
- case XmlNodeType.Element:
- CheckIndexCondition(attributeIndex);
- return ((XmlElement)_curNode).Attributes[attributeIndex].Value;
- case XmlNodeType.Attribute:
- CheckIndexCondition(attributeIndex);
- return ((XmlElement)_elemNode).Attributes[attributeIndex].Value;
- case XmlNodeType.XmlDeclaration:
- {
- CheckIndexCondition(attributeIndex);
- return GetDeclarationAttr(attributeIndex);
- }
- case XmlNodeType.DocumentType:
- {
- CheckIndexCondition(attributeIndex);
- return GetDocumentTypeAttr(attributeIndex);
- }
- }
- throw new ArgumentOutOfRangeException("attributeIndex"); //for other senario, AttributeCount is 0, i has to be out of range
- }
-
- public void LogMove(int level)
- {
- _logNode = _curNode;
- _nLogLevel = level;
- _nLogAttrInd = _nAttrInd;
- _logAttrIndex = _attrIndex;
- _bLogOnAttrVal = _bOnAttrVal;
- }
-
- //The function has to be used in pair with ResetMove when the operation fails after LogMove() is
- // called because it relies on the values of nOrigLevel, logNav and nOrigAttrInd to be acurate.
- public void RollBackMove(ref int level)
- {
- _curNode = _logNode;
- level = _nLogLevel;
- _nAttrInd = _nLogAttrInd;
- _attrIndex = _logAttrIndex;
- _bOnAttrVal = _bLogOnAttrVal;
- }
-
- private bool IsOnDeclOrDocType
- {
- get
- {
- XmlNodeType nt = _curNode.NodeType;
- return (nt == XmlNodeType.XmlDeclaration || nt == XmlNodeType.DocumentType);
- }
- }
-
- public void ResetToAttribute(ref int level)
- {
- //the current cursor is pointing at one of the attribute children -- this could be caused by
- // the calls to ReadAttributeValue(..)
- if (_bCreatedOnAttribute)
- return;
- if (_bOnAttrVal)
- {
- if (IsOnDeclOrDocType)
- {
- level -= 2;
- }
- else
- {
- while (_curNode.NodeType != XmlNodeType.Attribute && ((_curNode = _curNode.ParentNode) != null))
- level--;
- }
- _bOnAttrVal = false;
- }
- }
-
- public void ResetMove(ref int level, ref XmlNodeType nt)
- {
- LogMove(level);
- if (_bCreatedOnAttribute)
- return;
- if (_nAttrInd != -1)
- {
- Debug.Assert(IsOnDeclOrDocType);
- if (_bOnAttrVal)
- {
- level--;
- _bOnAttrVal = false;
- }
- _nLogAttrInd = _nAttrInd;
- level--;
- _nAttrInd = -1;
- nt = _curNode.NodeType;
- return;
- }
- if (_bOnAttrVal && _curNode.NodeType != XmlNodeType.Attribute)
- ResetToAttribute(ref level);
- if (_curNode.NodeType == XmlNodeType.Attribute)
- {
- _curNode = ((XmlAttribute)_curNode).OwnerElement;
- _attrIndex = -1;
- level--;
- nt = XmlNodeType.Element;
- }
- if (_curNode.NodeType == XmlNodeType.Element)
- _elemNode = _curNode;
- }
-
- public bool MoveToAttribute(string name)
- {
- return MoveToAttribute(name, string.Empty);
- }
- private bool MoveToAttributeFromElement(XmlElement elem, String name, String ns)
- {
- XmlAttribute attr = null;
- if (ns.Length == 0)
- attr = elem.GetAttributeNode(name);
- else
- attr = elem.GetAttributeNode(name, ns);
- if (attr != null)
- {
- _bOnAttrVal = false;
- _elemNode = elem;
- _curNode = attr;
- _attrIndex = elem.Attributes.FindNodeOffsetNS(attr);
- if (_attrIndex != -1)
- {
- return true;
- }
- }
- return false;
- }
-
- public bool MoveToAttribute(string name, string namespaceURI)
- {
- if (_bCreatedOnAttribute)
- return false;
- XmlNodeType nt = _curNode.NodeType;
- if (nt == XmlNodeType.Element)
- return MoveToAttributeFromElement((XmlElement)_curNode, name, namespaceURI);
- else if (nt == XmlNodeType.Attribute)
- return MoveToAttributeFromElement((XmlElement)_elemNode, name, namespaceURI);
- else if (nt == XmlNodeType.XmlDeclaration && namespaceURI.Length == 0)
- {
- if ((_nAttrInd = GetDecAttrInd(name)) != -1)
- {
- _bOnAttrVal = false;
- return true;
- }
- }
- else if (nt == XmlNodeType.DocumentType && namespaceURI.Length == 0)
- {
- if ((_nAttrInd = GetDocTypeAttrInd(name)) != -1)
- {
- _bOnAttrVal = false;
- return true;
- }
- }
- return false;
- }
-
- public void MoveToAttribute(int attributeIndex)
- {
- if (_bCreatedOnAttribute)
- return;
- XmlAttribute attr = null;
- switch (_curNode.NodeType)
- {
- case XmlNodeType.Element:
- CheckIndexCondition(attributeIndex);
- attr = ((XmlElement)_curNode).Attributes[attributeIndex];
- if (attr != null)
- {
- _elemNode = _curNode;
- _curNode = (XmlNode)attr;
- _attrIndex = attributeIndex;
- }
- break;
- case XmlNodeType.Attribute:
- CheckIndexCondition(attributeIndex);
- attr = ((XmlElement)_elemNode).Attributes[attributeIndex];
- if (attr != null)
- {
- _curNode = (XmlNode)attr;
- _attrIndex = attributeIndex;
- }
- break;
- case XmlNodeType.XmlDeclaration:
- case XmlNodeType.DocumentType:
- CheckIndexCondition(attributeIndex);
- _nAttrInd = attributeIndex;
- break;
- }
- }
-
- public bool MoveToNextAttribute(ref int level)
- {
- if (_bCreatedOnAttribute)
- return false;
- XmlNodeType nt = _curNode.NodeType;
- if (nt == XmlNodeType.Attribute)
- {
- if (_attrIndex >= (_elemNode.Attributes.Count - 1))
- return false;
- else
- {
- _curNode = _elemNode.Attributes[++_attrIndex];
- return true;
- }
- }
- else if (nt == XmlNodeType.Element)
- {
- if (_curNode.Attributes.Count > 0)
- {
- level++;
- _elemNode = _curNode;
- _curNode = _curNode.Attributes[0];
- _attrIndex = 0;
- return true;
- }
- }
- else if (nt == XmlNodeType.XmlDeclaration)
- {
- if (_nDeclarationAttrCount == -1)
- InitDecAttr();
- _nAttrInd++;
- if (_nAttrInd < _nDeclarationAttrCount)
- {
- if (_nAttrInd == 0) level++;
- _bOnAttrVal = false;
- return true;
- }
- _nAttrInd--;
- }
- else if (nt == XmlNodeType.DocumentType)
- {
- if (_nDocTypeAttrCount == -1)
- InitDocTypeAttr();
- _nAttrInd++;
- if (_nAttrInd < _nDocTypeAttrCount)
- {
- if (_nAttrInd == 0) level++;
- _bOnAttrVal = false;
- return true;
- }
- _nAttrInd--;
- }
- return false;
- }
-
- public bool MoveToParent()
- {
- XmlNode parent = _curNode.ParentNode;
- if (parent != null)
- {
- _curNode = parent;
- if (!_bOnAttrVal)
- _attrIndex = 0;
- return true;
- }
- return false;
- }
-
- public bool MoveToFirstChild()
- {
- XmlNode firstChild = _curNode.FirstChild;
- if (firstChild != null)
- {
- _curNode = firstChild;
- if (!_bOnAttrVal)
- _attrIndex = -1;
- return true;
- }
- return false;
- }
-
- private bool MoveToNextSibling(XmlNode node)
- {
- XmlNode nextSibling = node.NextSibling;
- if (nextSibling != null)
- {
- _curNode = nextSibling;
- if (!_bOnAttrVal)
- _attrIndex = -1;
- return true;
- }
- return false;
- }
-
- public bool MoveToNext()
- {
- if (_curNode.NodeType != XmlNodeType.Attribute)
- return MoveToNextSibling(_curNode);
- else
- return MoveToNextSibling(_elemNode);
- }
-
- public bool MoveToElement()
- {
- if (_bCreatedOnAttribute)
- return false;
- switch (_curNode.NodeType)
- {
- case XmlNodeType.Attribute:
- if (_elemNode != null)
- {
- _curNode = _elemNode;
- _attrIndex = -1;
- return true;
- }
- break;
- case XmlNodeType.XmlDeclaration:
- case XmlNodeType.DocumentType:
- {
- if (_nAttrInd != -1)
- {
- _nAttrInd = -1;
- return true;
- }
- break;
- }
- }
- return false;
- }
-
- public String LookupNamespace(string prefix)
- {
- if (_bCreatedOnAttribute)
- return null;
- if (prefix == "xmlns")
- {
- return _nameTable.Add(XmlReservedNs.NsXmlNs);
- }
- if (prefix == "xml")
- {
- return _nameTable.Add(XmlReservedNs.NsXml);
- }
-
- // construct the name of the xmlns attribute
- string attrName;
- if (prefix == null)
- prefix = string.Empty;
- if (prefix.Length == 0)
- attrName = "xmlns";
- else
- attrName = "xmlns:" + prefix;
-
- // walk up the XmlNode parent chain, looking for the xmlns attribute
- XmlNode node = _curNode;
- while (node != null)
- {
- if (node.NodeType == XmlNodeType.Element)
- {
- XmlElement elem = (XmlElement)node;
- if (elem.HasAttributes)
- {
- XmlAttribute attr = elem.GetAttributeNode(attrName);
- if (attr != null)
- {
- return attr.Value;
- }
- }
- }
- else if (node.NodeType == XmlNodeType.Attribute)
- {
- node = ((XmlAttribute)node).OwnerElement;
- continue;
- }
- node = node.ParentNode;
- }
- if (prefix.Length == 0)
- {
- return string.Empty;
- }
- return null;
- }
-
- internal string DefaultLookupNamespace(string prefix)
- {
- if (!_bCreatedOnAttribute)
- {
- if (prefix == "xmlns")
- {
- return _nameTable.Add(XmlReservedNs.NsXmlNs);
- }
- if (prefix == "xml")
- {
- return _nameTable.Add(XmlReservedNs.NsXml);
- }
- if (prefix == string.Empty)
- {
- return _nameTable.Add(string.Empty);
- }
- }
- return null;
- }
-
- internal String LookupPrefix(string namespaceName)
- {
- if (_bCreatedOnAttribute || namespaceName == null)
- {
- return null;
- }
- if (namespaceName == XmlReservedNs.NsXmlNs)
- {
- return _nameTable.Add("xmlns");
- }
- if (namespaceName == XmlReservedNs.NsXml)
- {
- return _nameTable.Add("xml");
- }
- if (namespaceName == string.Empty)
- {
- return string.Empty;
- }
- // walk up the XmlNode parent chain, looking for the xmlns attribute with namespaceName value
- XmlNode node = _curNode;
- while (node != null)
- {
- if (node.NodeType == XmlNodeType.Element)
- {
- XmlElement elem = (XmlElement)node;
- if (elem.HasAttributes)
- {
- XmlAttributeCollection attrs = elem.Attributes;
- for (int i = 0; i < attrs.Count; i++)
- {
- XmlAttribute a = attrs[i];
- if (a.Value == namespaceName)
- {
- if (a.Prefix.Length == 0 && a.LocalName == "xmlns")
- {
- if (LookupNamespace(string.Empty) == namespaceName)
- {
- return string.Empty;
- }
- }
- else if (a.Prefix == "xmlns")
- {
- string pref = a.LocalName;
- if (LookupNamespace(pref) == namespaceName)
- {
- return _nameTable.Add(pref);
- }
- }
- }
- }
- }
- }
- else if (node.NodeType == XmlNodeType.Attribute)
- {
- node = ((XmlAttribute)node).OwnerElement;
- continue;
- }
- node = node.ParentNode;
- }
- return null;
- }
-
- internal IDictionary GetNamespacesInScope(XmlNamespaceScope scope)
- {
- Dictionary dict = new Dictionary();
- if (_bCreatedOnAttribute)
- return dict;
-
- // walk up the XmlNode parent chain and add all namespace declarations to the dictionary
- XmlNode node = _curNode;
- while (node != null)
- {
- if (node.NodeType == XmlNodeType.Element)
- {
- XmlElement elem = (XmlElement)node;
- if (elem.HasAttributes)
- {
- XmlAttributeCollection attrs = elem.Attributes;
- for (int i = 0; i < attrs.Count; i++)
- {
- XmlAttribute a = attrs[i];
- if (a.LocalName == "xmlns" && a.Prefix.Length == 0)
- {
- if (!dict.ContainsKey(string.Empty))
- {
- dict.Add(_nameTable.Add(string.Empty), _nameTable.Add(a.Value));
- }
- }
- else if (a.Prefix == "xmlns")
- {
- string localName = a.LocalName;
- if (!dict.ContainsKey(localName))
- {
- dict.Add(_nameTable.Add(localName), _nameTable.Add(a.Value));
- }
- }
- }
- }
- if (scope == XmlNamespaceScope.Local)
- {
- break;
- }
- }
- else if (node.NodeType == XmlNodeType.Attribute)
- {
- node = ((XmlAttribute)node).OwnerElement;
- continue;
- }
- node = node.ParentNode;
- };
-
- if (scope != XmlNamespaceScope.Local)
- {
- if (dict.ContainsKey(string.Empty) && dict[string.Empty] == string.Empty)
- {
- dict.Remove(string.Empty);
- }
- if (scope == XmlNamespaceScope.All)
- {
- dict.Add(_nameTable.Add("xml"), _nameTable.Add(XmlReservedNs.NsXml));
- }
- }
- return dict;
- }
-
- public bool ReadAttributeValue(ref int level, ref bool bResolveEntity, ref XmlNodeType nt)
- {
- if (_nAttrInd != -1)
- {
- Debug.Assert(_curNode.NodeType == XmlNodeType.XmlDeclaration || _curNode.NodeType == XmlNodeType.DocumentType);
- if (!_bOnAttrVal)
- {
- _bOnAttrVal = true;
- level++;
- nt = XmlNodeType.Text;
- return true;
- }
- return false;
- }
- if (_curNode.NodeType == XmlNodeType.Attribute)
- {
- XmlNode firstChild = _curNode.FirstChild;
- if (firstChild != null)
- {
- _curNode = firstChild;
- nt = _curNode.NodeType;
- level++;
- _bOnAttrVal = true;
- return true;
- }
- }
- else if (_bOnAttrVal)
- {
- XmlNode nextSibling = null;
- if (_curNode.NodeType == XmlNodeType.EntityReference && bResolveEntity)
- {
- //going down to ent ref node
- _curNode = _curNode.FirstChild;
- nt = _curNode.NodeType;
- Debug.Assert(_curNode != null);
- level++;
- bResolveEntity = false;
- return true;
- }
- else
- nextSibling = _curNode.NextSibling;
- if (nextSibling == null)
- {
- XmlNode parentNode = _curNode.ParentNode;
- //Check if its parent is entity ref node is sufficient, because in this senario, ent ref node can't have more than 1 level of children that are not other ent ref nodes
- if (parentNode != null && parentNode.NodeType == XmlNodeType.EntityReference)
- {
- //come back from ent ref node
- _curNode = parentNode;
- nt = XmlNodeType.EndEntity;
- level--;
- return true;
- }
- }
- if (nextSibling != null)
- {
- _curNode = nextSibling;
- nt = _curNode.NodeType;
- return true;
- }
- else
- return false;
- }
- return false;
- }
-
- public XmlDocument Document
- {
- get
- {
- return _doc;
- }
- }
- }
-
- // Represents a reader that provides fast, non-cached forward only stream access
- // to XML data in an XmlDocument or a specific XmlNode within an XmlDocument.
- public class XmlNodeReader : XmlReader, IXmlNamespaceResolver
- {
- private XmlNodeReaderNavigator _readerNav;
-
- private XmlNodeType _nodeType; // nodeType of the node that the reader is currently positioned on
- private int _curDepth; // depth of attrNav ( also functions as reader's depth )
- private ReadState _readState; // current reader's state
- private bool _fEOF; // flag to show if reaches the end of file
- //mark to the state that EntityReference node is supposed to be resolved
- private bool _bResolveEntity;
- private bool _bStartFromDocument;
-
- private bool _bInReadBinary;
- private ReadContentAsBinaryHelper _readBinaryHelper;
-
-
- // Creates an instance of the XmlNodeReader class using the specified XmlNode.
- public XmlNodeReader(XmlNode node)
- {
- if (node == null)
- {
- throw new ArgumentNullException("node");
- }
- _readerNav = new XmlNodeReaderNavigator(node);
- _curDepth = 0;
-
- _readState = ReadState.Initial;
- _fEOF = false;
- _nodeType = XmlNodeType.None;
- _bResolveEntity = false;
- _bStartFromDocument = false;
- }
-
- //function returns if the reader currently in valid reading states
- internal bool IsInReadingStates()
- {
- return (_readState == ReadState.Interactive); // || readState == ReadState.EndOfFile
- }
-
- //
- // Node Properties
- //
-
- // Gets the type of the current node.
- public override XmlNodeType NodeType
- {
- get { return (IsInReadingStates()) ? _nodeType : XmlNodeType.None; }
- }
-
- // Gets the name of
- // the current node, including the namespace prefix.
- public override string Name
- {
- get
- {
- if (!IsInReadingStates())
- return String.Empty;
- return _readerNav.Name;
- }
- }
-
- // Gets the name of the current node without the namespace prefix.
- public override string LocalName
- {
- get
- {
- if (!IsInReadingStates())
- return String.Empty;
- return _readerNav.LocalName;
- }
- }
-
- // Gets the namespace URN (as defined in the W3C Namespace Specification)
- // of the current namespace scope.
- public override string NamespaceURI
- {
- get
- {
- if (!IsInReadingStates())
- return String.Empty;
- return _readerNav.NamespaceURI;
- }
- }
-
- // Gets the namespace prefix associated with the current node.
- public override string Prefix
- {
- get
- {
- if (!IsInReadingStates())
- return String.Empty;
- return _readerNav.Prefix;
- }
- }
-
- // Gets a value indicating whether
- // XmlNodeReader.Value has a value to return.
- public override bool HasValue
- {
- get
- {
- if (!IsInReadingStates())
- return false;
- return _readerNav.HasValue;
- }
- }
-
- // Gets the text value of the current node.
- public override string Value
- {
- get
- {
- if (!IsInReadingStates())
- return String.Empty;
- return _readerNav.Value;
- }
- }
-
- // Gets the depth of the
- // current node in the XML element stack.
- public override int Depth
- {
- get { return _curDepth; }
- }
-
- // Gets the base URI of the current node.
- public override String BaseURI
- {
- get { return _readerNav.BaseURI; }
- }
-
- public override bool CanResolveEntity
- {
- get { return true; }
- }
-
- // Gets a value indicating whether the current
- // node is an empty element (for example,