1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
//------------------------------------------------------------------------------
// <copyright file="DataDocumentXPathNavigator.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
// <owner current="true" primary="false">Microsoft</owner>
//------------------------------------------------------------------------------
#pragma warning disable 618 // ignore obsolete warning about XmlDataDocument
namespace System.Xml {
using System;
using System.Xml.XPath;
internal sealed class DataDocumentXPathNavigator: XPathNavigator, IHasXmlNode {
private XPathNodePointer _curNode; //pointer to remember the current node position
private XmlDataDocument _doc; //pointer to remember the root -- can only be XmlDataDocument for DataDocumentXPathNavigator
private XPathNodePointer _temp;
internal DataDocumentXPathNavigator( XmlDataDocument doc, XmlNode node ) {
_curNode = new XPathNodePointer( this, doc, node );
_temp = new XPathNodePointer( this, doc, node );
_doc = doc;
}
private DataDocumentXPathNavigator( DataDocumentXPathNavigator other ) {
this._curNode = other._curNode.Clone( this );
this._temp = other._temp.Clone( this );
this._doc = other._doc;
}
public override XPathNavigator Clone(){
return new DataDocumentXPathNavigator( this );
}
internal XPathNodePointer CurNode { get { return _curNode; } }
internal XmlDataDocument Document { get { return _doc; } }
//Convert will deal with nodeType as Attribute or Namespace nodes
public override XPathNodeType NodeType { get { return _curNode.NodeType; } }
public override string LocalName { get { return _curNode.LocalName; } }
public override string NamespaceURI { get { return _curNode.NamespaceURI; } }
public override string Name { get { return _curNode.Name; } }
public override string Prefix { get { return _curNode.Prefix; } }
public override string Value {
get {
XPathNodeType xnt = _curNode.NodeType;
if ( xnt == XPathNodeType.Element || xnt == XPathNodeType.Root )
return _curNode.InnerText;
return _curNode.Value;
}
}
public override String BaseURI { get { return _curNode.BaseURI; } }
public override String XmlLang { get { return _curNode.XmlLang; } }
public override bool IsEmptyElement { get { return _curNode.IsEmptyElement; } }
public override XmlNameTable NameTable { get { return _doc.NameTable; } }
// Attributes
public override bool HasAttributes { get { return _curNode.AttributeCount > 0; } }
public override string GetAttribute( string localName, string namespaceURI ) {
if ( _curNode.NodeType != XPathNodeType.Element )
return string.Empty; //other type of nodes can't have attributes
_temp.MoveTo( _curNode );
if ( _temp.MoveToAttribute( localName, namespaceURI ) )
return _temp.Value;
return string.Empty;
}
//#if SupportNamespaces
public override string GetNamespace(string name) {
return _curNode.GetNamespace( name );
}
public override bool MoveToNamespace(string name) {
if ( _curNode.NodeType != XPathNodeType.Element )
return false;
return _curNode.MoveToNamespace( name );
}
public override bool MoveToFirstNamespace(XPathNamespaceScope namespaceScope) {
if ( _curNode.NodeType != XPathNodeType.Element )
return false;
return _curNode.MoveToFirstNamespace(namespaceScope);
}
public override bool MoveToNextNamespace(XPathNamespaceScope namespaceScope) {
if ( _curNode.NodeType != XPathNodeType.Namespace )
return false;
return _curNode.MoveToNextNamespace(namespaceScope);
}
//#endif
public override bool MoveToAttribute( string localName, string namespaceURI ) {
if ( _curNode.NodeType != XPathNodeType.Element )
return false; //other type of nodes can't have attributes
return _curNode.MoveToAttribute( localName, namespaceURI );
}
public override bool MoveToFirstAttribute() {
if ( _curNode.NodeType != XPathNodeType.Element )
return false; //other type of nodes can't have attributes
return _curNode.MoveToNextAttribute(true);
}
public override bool MoveToNextAttribute() {
if ( _curNode.NodeType != XPathNodeType.Attribute )
return false;
return _curNode.MoveToNextAttribute(false);
}
// Tree
public override bool MoveToNext() {
if ( _curNode.NodeType == XPathNodeType.Attribute )
return false;
return _curNode.MoveToNextSibling();
}
public override bool MoveToPrevious() {
if ( _curNode.NodeType == XPathNodeType.Attribute )
return false;
return _curNode.MoveToPreviousSibling();
}
public override bool MoveToFirst() {
if ( _curNode.NodeType == XPathNodeType.Attribute )
return false;
return _curNode.MoveToFirst();
}
public override bool HasChildren { get { return _curNode.HasChildren; } }
public override bool MoveToFirstChild() {
return _curNode.MoveToFirstChild();
}
public override bool MoveToParent() {
return _curNode.MoveToParent();
}
public override void MoveToRoot() {
_curNode.MoveToRoot();
}
public override bool MoveTo( XPathNavigator other ) {
if ( other == null )
return false;
DataDocumentXPathNavigator otherDataDocXPathNav = other as DataDocumentXPathNavigator;
if ( otherDataDocXPathNav != null ) {
if ( _curNode.MoveTo( otherDataDocXPathNav.CurNode ) ) {
_doc = _curNode.Document;
return true;
}
else
return false;
}
return false;
}
//doesn't support MoveToId
public override bool MoveToId( string id ) {
return false;
}
public override bool IsSamePosition( XPathNavigator other ) {
if ( other == null )
return false;
DataDocumentXPathNavigator otherDataDocXPathNav = other as DataDocumentXPathNavigator;
if ( otherDataDocXPathNav != null ) {
if ( this._doc == otherDataDocXPathNav.Document && this._curNode.IsSamePosition(otherDataDocXPathNav.CurNode) )
return true;
}
return false;
}
//the function is only called for XPathNodeList enumerate nodes and
// shouldn't be promoted to frequently use because it will cause foliation
XmlNode IHasXmlNode.GetNode() { return _curNode.Node; }
public override XmlNodeOrder ComparePosition( XPathNavigator other ) {
if ( other == null )
return XmlNodeOrder.Unknown; // this is what XPathDocument does. // WebData 103403
DataDocumentXPathNavigator otherDataDocXPathNav = other as DataDocumentXPathNavigator;
if ( otherDataDocXPathNav == null || otherDataDocXPathNav.Document != this._doc )
return XmlNodeOrder.Unknown;
return this._curNode.ComparePosition( otherDataDocXPathNav.CurNode );
}
}
}
|