1 //------------------------------------------------------------------------------
2 // <copyright file="DataDocumentXPathNavigator.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">[....]</owner>
6 // <owner current="true" primary="false">[....]</owner>
7 //------------------------------------------------------------------------------
8 #pragma warning disable 618 // ignore obsolete warning about XmlDataDocument
11 using System.Xml.XPath;
13 internal sealed class DataDocumentXPathNavigator: XPathNavigator, IHasXmlNode {
14 private XPathNodePointer _curNode; //pointer to remember the current node position
15 private XmlDataDocument _doc; //pointer to remember the root -- can only be XmlDataDocument for DataDocumentXPathNavigator
16 private XPathNodePointer _temp;
18 internal DataDocumentXPathNavigator( XmlDataDocument doc, XmlNode node ) {
19 _curNode = new XPathNodePointer( this, doc, node );
20 _temp = new XPathNodePointer( this, doc, node );
24 private DataDocumentXPathNavigator( DataDocumentXPathNavigator other ) {
25 this._curNode = other._curNode.Clone( this );
26 this._temp = other._temp.Clone( this );
27 this._doc = other._doc;
29 public override XPathNavigator Clone(){
30 return new DataDocumentXPathNavigator( this );
33 internal XPathNodePointer CurNode { get { return _curNode; } }
34 internal XmlDataDocument Document { get { return _doc; } }
36 //Convert will deal with nodeType as Attribute or Namespace nodes
37 public override XPathNodeType NodeType { get { return _curNode.NodeType; } }
39 public override string LocalName { get { return _curNode.LocalName; } }
41 public override string NamespaceURI { get { return _curNode.NamespaceURI; } }
43 public override string Name { get { return _curNode.Name; } }
45 public override string Prefix { get { return _curNode.Prefix; } }
47 public override string Value {
49 XPathNodeType xnt = _curNode.NodeType;
50 if ( xnt == XPathNodeType.Element || xnt == XPathNodeType.Root )
51 return _curNode.InnerText;
52 return _curNode.Value;
56 public override String BaseURI { get { return _curNode.BaseURI; } }
58 public override String XmlLang { get { return _curNode.XmlLang; } }
60 public override bool IsEmptyElement { get { return _curNode.IsEmptyElement; } }
62 public override XmlNameTable NameTable { get { return _doc.NameTable; } }
65 public override bool HasAttributes { get { return _curNode.AttributeCount > 0; } }
67 public override string GetAttribute( string localName, string namespaceURI ) {
68 if ( _curNode.NodeType != XPathNodeType.Element )
69 return string.Empty; //other type of nodes can't have attributes
70 _temp.MoveTo( _curNode );
71 if ( _temp.MoveToAttribute( localName, namespaceURI ) )
76 //#if SupportNamespaces
78 public override string GetNamespace(string name) {
79 return _curNode.GetNamespace( name );
82 public override bool MoveToNamespace(string name) {
83 if ( _curNode.NodeType != XPathNodeType.Element )
85 return _curNode.MoveToNamespace( name );
88 public override bool MoveToFirstNamespace(XPathNamespaceScope namespaceScope) {
89 if ( _curNode.NodeType != XPathNodeType.Element )
91 return _curNode.MoveToFirstNamespace(namespaceScope);
94 public override bool MoveToNextNamespace(XPathNamespaceScope namespaceScope) {
95 if ( _curNode.NodeType != XPathNodeType.Namespace )
97 return _curNode.MoveToNextNamespace(namespaceScope);
101 public override bool MoveToAttribute( string localName, string namespaceURI ) {
102 if ( _curNode.NodeType != XPathNodeType.Element )
103 return false; //other type of nodes can't have attributes
104 return _curNode.MoveToAttribute( localName, namespaceURI );
107 public override bool MoveToFirstAttribute() {
108 if ( _curNode.NodeType != XPathNodeType.Element )
109 return false; //other type of nodes can't have attributes
110 return _curNode.MoveToNextAttribute(true);
113 public override bool MoveToNextAttribute() {
114 if ( _curNode.NodeType != XPathNodeType.Attribute )
116 return _curNode.MoveToNextAttribute(false);
121 public override bool MoveToNext() {
122 if ( _curNode.NodeType == XPathNodeType.Attribute )
124 return _curNode.MoveToNextSibling();
127 public override bool MoveToPrevious() {
128 if ( _curNode.NodeType == XPathNodeType.Attribute )
130 return _curNode.MoveToPreviousSibling();
133 public override bool MoveToFirst() {
134 if ( _curNode.NodeType == XPathNodeType.Attribute )
136 return _curNode.MoveToFirst();
139 public override bool HasChildren { get { return _curNode.HasChildren; } }
141 public override bool MoveToFirstChild() {
142 return _curNode.MoveToFirstChild();
145 public override bool MoveToParent() {
146 return _curNode.MoveToParent();
149 public override void MoveToRoot() {
150 _curNode.MoveToRoot();
153 public override bool MoveTo( XPathNavigator other ) {
156 DataDocumentXPathNavigator otherDataDocXPathNav = other as DataDocumentXPathNavigator;
157 if ( otherDataDocXPathNav != null ) {
158 if ( _curNode.MoveTo( otherDataDocXPathNav.CurNode ) ) {
159 _doc = _curNode.Document;
168 //doesn't support MoveToId
169 public override bool MoveToId( string id ) {
173 public override bool IsSamePosition( XPathNavigator other ) {
176 DataDocumentXPathNavigator otherDataDocXPathNav = other as DataDocumentXPathNavigator;
177 if ( otherDataDocXPathNav != null ) {
178 if ( this._doc == otherDataDocXPathNav.Document && this._curNode.IsSamePosition(otherDataDocXPathNav.CurNode) )
184 //the function is only called for XPathNodeList enumerate nodes and
185 // shouldn't be promoted to frequently use because it will cause foliation
186 XmlNode IHasXmlNode.GetNode() { return _curNode.Node; }
188 public override XmlNodeOrder ComparePosition( XPathNavigator other ) {
190 return XmlNodeOrder.Unknown; // this is what XPathDocument does. // WebData 103403
192 DataDocumentXPathNavigator otherDataDocXPathNav = other as DataDocumentXPathNavigator;
194 if ( otherDataDocXPathNav == null || otherDataDocXPathNav.Document != this._doc )
195 return XmlNodeOrder.Unknown;
197 return this._curNode.ComparePosition( otherDataDocXPathNav.CurNode );