| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- //
- // System.Xml.XmlDocumentNavigator
- //
- // Author:
- // Jason Diamond <[email protected]>
- //
- // (C) 2002 Jason Diamond
- //
- using System;
- using System.Collections;
- using System.Xml;
- using System.Xml.XPath;
- namespace System.Xml
- {
- internal class XmlDocumentNavigator : XPathNavigator
- {
- #region Constructors
- [MonoTODO]
- internal XmlDocumentNavigator(XmlNode node)
- {
- this.node = node;
- }
- #endregion
- #region Fields
- private XmlNode node;
- private IEnumerator attributesEnumerator;
- #endregion
- #region Properties
- [MonoTODO]
- public override string BaseURI {
- get {
- throw new NotImplementedException ();
- }
- }
- public override bool HasAttributes {
- get {
- if (node.Attributes != null)
- foreach (XmlAttribute attribute in node.Attributes)
- if (attribute.NamespaceURI != "http://www.w3.org/2000/xmlns/")
- return true;
- return false;
- }
- }
- public override bool HasChildren {
- get {
- XPathNodeType nodeType = NodeType;
- bool canHaveChildren = nodeType == XPathNodeType.Root || nodeType == XPathNodeType.Element;
- return canHaveChildren && node.FirstChild != null;
- }
- }
- public override bool IsEmptyElement {
- get {
- return node.NodeType == XmlNodeType.Element && !HasChildren;
- }
- }
- public override string LocalName {
- get {
- XPathNodeType nodeType = NodeType;
- bool canHaveName =
- nodeType == XPathNodeType.Element ||
- nodeType == XPathNodeType.Attribute ||
- nodeType == XPathNodeType.ProcessingInstruction ||
- nodeType == XPathNodeType.Namespace;
- return canHaveName ? node.LocalName : String.Empty;
- }
- }
- public override string Name {
- get {
- XPathNodeType nodeType = NodeType;
- bool canHaveName =
- nodeType == XPathNodeType.Element ||
- nodeType == XPathNodeType.Attribute ||
- nodeType == XPathNodeType.ProcessingInstruction ||
- nodeType == XPathNodeType.Namespace;
- return canHaveName ? node.Name : String.Empty;
- }
- }
- public override string NamespaceURI {
- get {
- return node.NamespaceURI;
- }
- }
- [MonoTODO]
- public override XmlNameTable NameTable {
- get {
- throw new NotImplementedException ();
- }
- }
- public override XPathNodeType NodeType {
- get {
- return node.XPathNodeType;
- }
- }
- public override string Prefix {
- get {
- return node.Prefix;
- }
- }
- public override string Value {
- get {
- switch (NodeType) {
- case XPathNodeType.Attribute:
- case XPathNodeType.Comment:
- case XPathNodeType.ProcessingInstruction:
- case XPathNodeType.Text:
- case XPathNodeType.Whitespace:
- case XPathNodeType.SignificantWhitespace:
- return node.Value;
- case XPathNodeType.Element:
- case XPathNodeType.Root:
- return node.InnerText;
- }
- return String.Empty;
- }
- }
- [MonoTODO]
- public override string XmlLang {
- get {
- throw new NotImplementedException ();
- }
- }
- #endregion
- #region Methods
- public override XPathNavigator Clone ()
- {
- return new XmlDocumentNavigator (node);
- }
- [MonoTODO]
- public override string GetAttribute (string localName, string namespaceURI)
- {
- throw new NotImplementedException ();
- }
- [MonoTODO]
- public override string GetNamespace (string name)
- {
- throw new NotImplementedException ();
- }
-
- public override bool IsSamePosition (XPathNavigator other)
- {
- XmlDocumentNavigator otherDocumentNavigator = other as XmlDocumentNavigator;
- if (otherDocumentNavigator != null)
- return node == otherDocumentNavigator.node;
- return false;
- }
- public override bool MoveTo (XPathNavigator other)
- {
- XmlDocumentNavigator otherDocumentNavigator = other as XmlDocumentNavigator;
- if (otherDocumentNavigator != null) {
- if (node.OwnerDocument == otherDocumentNavigator.node.OwnerDocument) {
- node = otherDocumentNavigator.node;
- return true;
- }
- }
- return false;
- }
- [MonoTODO]
- public override bool MoveToAttribute (string localName, string namespaceURI)
- {
- throw new NotImplementedException ();
- }
- public override bool MoveToFirst ()
- {
- if (node.NodeType != XmlNodeType.Attribute && node.ParentNode != null) {
- node = node.ParentNode.FirstChild;
- return true;
- }
- return false;
- }
- public override bool MoveToFirstAttribute ()
- {
- if (NodeType == XPathNodeType.Element) {
- attributesEnumerator = node.Attributes.GetEnumerator ();
- return MoveToNextAttribute ();
- }
- return false;
- }
- public override bool MoveToFirstChild ()
- {
- if (HasChildren) {
- node = node.FirstChild;
- return true;
- }
- return false;
- }
- [MonoTODO]
- public override bool MoveToFirstNamespace (XPathNamespaceScope namespaceScope)
- {
- throw new NotImplementedException ();
- }
- public override bool MoveToId (string id)
- {
- XmlDocument doc;
-
- if (node.NodeType == XmlNodeType.Document)
- doc = (XmlDocument) node;
- else
- doc = node.OwnerDocument;
- XmlElement eltNew = doc.GetElementById (id);
- if (eltNew == null)
- return false;
- node = eltNew;
- return true;
- }
- [MonoTODO]
- public override bool MoveToNamespace (string name)
- {
- throw new NotImplementedException ();
- }
- public override bool MoveToNext ()
- {
- if (node.NextSibling != null) {
- node = node.NextSibling;
- return true;
- }
- return false;
- }
- public override bool MoveToNextAttribute ()
- {
- if (attributesEnumerator != null && attributesEnumerator.MoveNext ()) {
- node = attributesEnumerator.Current as XmlAttribute;
- return true;
- }
- return false;
- }
- [MonoTODO]
- public override bool MoveToNextNamespace (XPathNamespaceScope namespaceScope)
- {
- throw new NotImplementedException ();
- }
- public override bool MoveToParent ()
- {
- if (node.NodeType == XmlNodeType.Attribute) {
- XmlElement ownerElement = ((XmlAttribute)node).OwnerElement;
- if (ownerElement != null) {
- node = ownerElement;
- return true;
- }
- } else if (node.ParentNode != null) {
- node = node.ParentNode;
- return true;
- }
- return false;
- }
- public override bool MoveToPrevious ()
- {
- if (node.PreviousSibling != null) {
- node = node.PreviousSibling;
- return true;
- }
- return false;
- }
- public override void MoveToRoot ()
- {
- if (node.NodeType != XmlNodeType.Document)
- node = node.OwnerDocument;
- }
- internal XmlNode Node { get { return node; } }
- #endregion
- }
- }
|