/// <include file='doc\XPathDocumentView.uex' path='docs/doc[@for="XPathDocumentView.XPathDocumentView4"]/*' />
 public XPathDocumentView(XPathDocument document, string xpath, IXmlNamespaceResolver namespaceResolver, bool showPrefixes) {
     if (null == document)
         throw new ArgumentNullException("document");
     this.xpath = xpath;
     this.document = document;
     this.ndRoot = document.Root;
     if (null == this.ndRoot)
         throw new ArgumentException("document");
     this.ndRoot = document.Root;
     this.xpathResolver = namespaceResolver;
     if (showPrefixes)
         this.namespaceResolver = namespaceResolver;
     ArrayList rows = new ArrayList();
     this.rows = rows;
     InitFromXPath(this.ndRoot, xpath);
 }
 /// <include file='doc\XPathDocumentView.uex' path='docs/doc[@for="XPathDocumentView.XPathDocumentView1"]/*' />
 public XPathDocumentView(XPathDocument document, IXmlNamespaceResolver namespaceResolver) {
     if (null == document)
         throw new ArgumentNullException("document");
     this.document = document;
     this.ndRoot = document.Root;
     if (null == this.ndRoot)
         throw new ArgumentException("document");
     this.namespaceResolver = namespaceResolver;
     ArrayList rows = new ArrayList();
     this.rows = rows;
     Debug.Assert(XPathNodeType.Root == this.ndRoot.NodeType);
     XPathNode nd = this.ndRoot.Child;
     while (null != nd) {
         if (XPathNodeType.Element == nd.NodeType) 
             rows.Add(nd);
         nd = nd.Sibling;
     }
     DeriveShapeFromRows();
 }
Example #3
0
        public override bool MoveTo( XPathNavigator other ) {
		    XPathDocumentNavigator nav = other as XPathDocumentNavigator;
		    if( nav != null ) {
			    doc = nav.doc;
			    node = nav.node;
			    return true;				
		    }
		    return false;
	    }
Example #4
0
		protected IXmlCursor Cursor(XPathNavigator parent, string pathText, CursorFlags flags)
		{
			var parentNode = new XPathNode(parent, typeof(object), NamespaceSource.Instance);
			var compiledPath = XPathCompiler.Compile(pathText);
			compiledPath.SetContext(Context);
			return Cursor(parentNode, compiledPath, IncludedTypes, flags);
		}
 internal XPathDocumentView(XPathNode root, ArrayList rows, Shape rowShape) {
     this.rows = rows;
     this.rowShape = rowShape;
     this.ndRoot = root;
 }
 public bool Next() {
     if (null != this.node) {
         this.node = TreeNavigationHelper.GetContentSibling(this.node, XPathNodeType.Element);
         if (node != null)
             Advance();                    
         return null != this.node;
     }
     return false;
 }
 public ContentIterator(XPathNode nd, Shape shape) {
     this.node = nd;
     XmlSchemaElement xse = shape.XmlSchemaElement;
     Debug.Assert(null != xse);
     SchemaElementDecl decl = xse.ElementDecl;
     Debug.Assert(null != decl);
     this.contentValidator = decl.ContentValidator;
     this.currentState = new ValidationState();
     this.contentValidator.InitValidation(this.currentState);
     this.currentState.ProcessContents = XmlSchemaContentProcessing.Strict;
     if (nd != null)
         Advance();
 }
        //
        // XPath support
        //

        void InitFromXPath(XPathNode ndRoot, string xpath) {
            XPathStep[] steps = ParseXPath(xpath, this.xpathResolver);
            ArrayList rows = this.rows;
            rows.Clear();
            PopulateFromXPath(ndRoot, steps, 0);
            DeriveShapeFromRows();
        }
Example #9
0
	    private XPathDocumentNavigator( XPathDocumentNavigator nav ) {
            this.doc = nav.doc;
            this.node = nav.node;
            this.parentOfNs = nav.parentOfNs;
	    }
Example #10
0
	    internal XPathDocumentNavigator( XPathDocument doc, XPathNode node ) {
            this.doc = doc;
            this.node = node;
	    }
Example #11
0
        public void RemoveChild( XPathNode node ) {
            Debug.Assert( node.ParentNode == this );
            XPathNode nodePrev = node.previous;
            XPathNode nodeNext = node.next;

            if( nodePrev != null ) {
                nodePrev.next = nodeNext;
            }
            if( nodeNext != null ) {
                nodeNext.previous = nodePrev;                
                Debug.Assert( this.lastChild != node, "Node has next. It can't be last child of it's parent." );
            }
            else {
                if( this.lastChild == node ) {
                    this.lastChild = nodePrev;
                }
            }
            if( this.firstChild == node ) {
                this.firstChild = nodeNext;
            }
        }
Example #12
0
 public void AppendChild( XPathNode node ) {
     if( this.lastChild != null ) {
         node.previous = this.lastChild;
         this.lastChild.next = node;
         this.lastChild = node;
     }
     else {
         this.lastChild = node;
         this.firstChild = node;
     }
     node.parent = this;
 }
Example #13
0
 protected bool Match(XPathNode node, string name, string nsUri) {
     Debug.Assert(node != null);
     return node.IsElement(name, nsUri);
 }
Example #14
0
        public override bool MoveToId( string id ) {
		    XPathNode n = doc.GetElementFromId( id );
		    if ( n != null ) {
		        node = n;
		        return true;
	        }
	        return false;
	    }   
Example #15
0
        public override bool MoveToParent() {
            if (parentOfNs != null) {
                node = parentOfNs; // namespace trick
                parentOfNs = null;
                return true;
            }
            else {
                XPathNode n = node.ParentNode;
                if( n != null ) {
			        node = n;
			        return true;
		        }
            }
		    return false;
	    }
        XPathNodeView FillRow(XPathNode ndRow, Shape shape) {
            object[] columns;
            XPathNode nd;
            switch (shape.BindingType) {
                case BindingType.Text:
                case BindingType.Attribute:
                    columns = new object[1];
                    columns[0] = ndRow;
                    return new XPathNodeView(this, ndRow, columns);

                case BindingType.Repeat:
                    columns = new object[1];
                    nd = TreeNavigationHelper.GetContentChild(ndRow);
                    columns[0] = FillColumn(new ContentIterator(nd, shape), shape);
                    return new XPathNodeView(this, ndRow, columns);

                case BindingType.Sequence:
                case BindingType.Choice:
                case BindingType.All:
                    int subShapesCount = shape.SubShapes.Count;
                    columns = new object[subShapesCount];
                    if (shape.BindingType == BindingType.Sequence
                        && shape.SubShape(0).BindingType == BindingType.Attribute) {
                        FillAttributes(ndRow, shape, columns);
                    }
                    Shape lastSubShape = (Shape)shape.SubShapes[subShapesCount - 1];
                    if (lastSubShape.BindingType == BindingType.Text) { //Attributes followed by simpe content or mixed content
                        columns[subShapesCount - 1] = ndRow;
                        return new XPathNodeView(this, ndRow, columns);
                    }
                    else {
                        nd = TreeNavigationHelper.GetContentChild(ndRow);
                        return FillSubRow(new ContentIterator(nd, shape), shape, columns);
                    }

                default:
                    // should not map to a row
#if DEBUG
                    throw new NotSupportedException("Unable to bind row to: "+shape.BindingType.ToString());
#else
                    throw new NotSupportedException();
#endif
            }
        }
Example #17
0
        public override bool MoveToAttribute( string localName, string namespaceURI ) {
            XPathNode n = node.GetAttribute(localName, namespaceURI);
            if( n != null ) {
                node = n;
                return true;
            }
		    return false;
	    }
 void FillAttributes(XPathNode nd, Shape shape, object[] cols) {
     int i = 0;
     while (i < cols.Length) {
         Shape attrShape = shape.SubShape(i);
         if (attrShape.BindingType != BindingType.Attribute)
             break;
         XmlQualifiedName name = attrShape.AttributeName;
         XPathNode ndAttr = nd.GetAttribute( name.Name, name.Namespace );
         if (null != ndAttr)
             cols[i] = ndAttr;
         i++;
     }
 }
Example #19
0
 public override bool MoveToNextAttribute() {
     XPathNode n = node.NextAttributeNode;
     if( n != null ) {
         node = n;
         return true;
     }
     return false;
 }
 void PopulateFromXPath(XPathNode nd, XPathStep[] steps, int step) {
     string ln = steps[step].name.Name;
     string ns = steps[step].name.Namespace;
     if (XPathNodeType.Attribute == steps[step].type) {
         XPathNode ndAttr = nd.GetAttribute( ln, ns, true);
         if (null != ndAttr) {
             if (null != ndAttr.SchemaAttribute)
                 this.rows.Add(ndAttr);
         }
     }
     else {
         XPathNode ndChild = TreeNavigationHelper.GetElementChild(nd, ln, ns, true);
         if (null != ndChild) {
             int nextStep = step+1;
             do {
                 if (steps.Length == nextStep) {
                     if (null != ndChild.SchemaType)
                         this.rows.Add(ndChild);
                 }
                 else {
                     PopulateFromXPath(ndChild, steps, nextStep);
                 }
                 ndChild = TreeNavigationHelper.GetElementSibling(ndChild, ln, ns, true);
             } while (null != ndChild);
         }
     }
 }
Example #21
0
        public override bool MoveToNamespace(string name) {
		    XPathNamespace ns = node.GetNamespace(name);
            if( ns != null ) {
                parentOfNs = node;
                node = ns;
                return true;
            }
            return false;
        }
Example #22
0
 public override bool MoveToNextNamespace(XPathNamespaceScope namespaceScope) { 
     XPathNode n = node.NextNamespaceNode;
     if (n != null) {
         XPathNode parent = n.parent;
         if (parent == null && namespaceScope == XPathNamespaceScope.ExcludeXml) {
             return false;
         }
         if (parent != parentOfNs && namespaceScope == XPathNamespaceScope.Local) {
             return false;
         }
         node = n;
         return true;
     }
     return false;
 }
Example #23
0
        public override bool MoveToPrevious() {
            XPathNode n = node.PreviousSiblingNode;
            if( n != null ) {
			    node = n;
			    return true;
		    }
		    return false;
	    }
 private void Advance() {
     XPathNode nd = this.node;
     int errorCode;
     this.currentParticle = this.contentValidator.ValidateElement(new XmlQualifiedName(nd.LocalName, nd.NamespaceUri), this.currentState, out errorCode);
     if (null == this.currentParticle || 0 != errorCode) {
         this.node = null;
     }
 }
Example #25
0
        public override bool MoveToFirst() {
            XPathNode n = node.FirstSiblingNode;
            if( n != null ) {
		        node = n;
		        return true;
		    }
		    return false;
	    }
Example #26
0
		public void MoveTo_NotARecognizedNode_Fails()
		{
			var xml    = Xml("<X/>");
			var cursor = Cursor(xml, "A", CursorFlags.Multiple);

			var wrongNode = new XPathNode(Xml("<Q/>"), typeof(object), NamespaceSource.Instance);

			Assert.Throws<InvalidOperationException>(() =>
				cursor.MoveTo(wrongNode));
		}
Example #27
0
        public override bool MoveToFirstChild() {
            XPathNode n = node.FirstChildNode;
            if( n != null ) {
                //Debug.Assert(n.NodeType != XPathNodeType.Attribute, "Attribute is child");
			    node = n;
			    return true;
		    }
		    return false;
	    }
Example #28
0
 internal XPathNodeView(XPathDocumentView col, XPathNode rowNd, object[] columns) {
     this.collection = col;
     this.rowNd = rowNd;
     this.cols = columns;
 }
Example #29
0
        public override void MoveToRoot() {
            parentOfNs = null;
		    node = doc.root;
	    }