Ejemplo n.º 1
0
        /// <summary>
        /// Compares xsi:type attribute values
        /// </summary>
        private ComparisonState CompareXsiType(XmlAttribute control,
                                               XPathContext controlContext,
                                               XmlAttribute test,
                                               XPathContext testContext)
        {
            bool mustChangeControlContext = control != null;
            bool mustChangeTestContext    = test != null;

            if (!mustChangeControlContext && !mustChangeTestContext)
            {
                return(new OngoingComparisonState(this));
            }
            bool attributePresentOnBothSides = mustChangeControlContext &&
                                               mustChangeTestContext;

            try {
                XmlQualifiedName controlAttrName = null;
                if (mustChangeControlContext)
                {
                    controlAttrName = control.GetQName();
                    controlContext.AddAttribute(controlAttrName);
                    controlContext.NavigateToAttribute(controlAttrName);
                }
                XmlQualifiedName testAttrName = null;
                if (mustChangeTestContext)
                {
                    testAttrName = test.GetQName();
                    testContext.AddAttribute(testAttrName);
                    testContext.NavigateToAttribute(testAttrName);
                }
                return(Compare(new Comparison(ComparisonType.ATTR_NAME_LOOKUP,
                                              control, GetXPath(controlContext),
                                              controlAttrName,
                                              GetParentXPath(controlContext),
                                              test, GetXPath(testContext),
                                              testAttrName, GetParentXPath(testContext)))
                       .AndIfTrueThen(attributePresentOnBothSides,
                                      () => CompareAttributeExplicitness(control, controlContext,
                                                                         test, testContext))
                       .AndIfTrueThen(attributePresentOnBothSides,
                                      new Comparison(ComparisonType.ATTR_VALUE,
                                                     control, GetXPath(controlContext),
                                                     ValueAsQName(control),
                                                     GetParentXPath(controlContext),
                                                     test, GetXPath(testContext),
                                                     ValueAsQName(test),
                                                     GetParentXPath(testContext))));
            } finally {
                if (mustChangeControlContext)
                {
                    controlContext.NavigateToParent();
                }
                if (mustChangeTestContext)
                {
                    testContext.NavigateToParent();
                }
            }
        }
Ejemplo n.º 2
0
        private XPathContext GetXPathForAttribute(XmlAttribute a)
        {
            XPathContext     elementContext = GetXPathForNonAttribute(a.OwnerElement);
            XmlQualifiedName q = Nodes.GetQName(a);

            elementContext.AddAttribute(q);
            elementContext.NavigateToAttribute(q);
            return(elementContext);
        }
Ejemplo n.º 3
0
        public void singleAttribute()
        {
            XPathContext ctx = new XPathContext();

            ctx.SetChildren(Linqy.Singleton(new Element("foo")));
            ctx.NavigateToChild(0);
            ctx.AddAttribute(new XmlQualifiedName("bar"));
            ctx.NavigateToAttribute(new XmlQualifiedName("bar"));
            Assert.AreEqual("/foo[1]/@bar", ctx.XPath);
            Assert.AreEqual("/foo[1]", ctx.ParentXPath);
        }