public void NaiveXPathElement_Intersect_AttributeComparison()
        {
            NaiveXPathBuilder.NaiveXPathElement e1 = new NaiveXPathBuilder.NaiveXPathElement("name");
            NaiveXPathBuilder.NaiveXPathElement e2 = new NaiveXPathBuilder.NaiveXPathElement("name");

            // Si deux éléments ont des attributs avec le
            // même nom et la même valeur, on doit les
            // retouver dans l'intersection
            e1.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr1", "value"));
            e2.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr1", "value"));

            // Si deux éléments ont des attributs avec le
            // même nom, mais des valeurs différentes, on
            // doit retrouver un attribut avec le même nom
            // (mais sans valeur définie) dans la solution
            e1.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr2", "value1"));
            e2.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr2", "value2"));

            // Un attribut de e1 qui n'existe pas dans e2,
            // (et inversement), ne se retrouve
            // pas dans la solution.
            e1.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr3", "value"));
            e2.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr4", "value"));

            // La solution ne tient pas compte
            // des attributs qui existeraient
            // en plusieurs exemplaires dans l'un
            // ou l'autre des éléments. D'ailleurs,
            // ce cas de figure ne devrait même pas
            // se présenter !
            e1.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr5", "value1"));
            e1.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr5", "value2"));
            e2.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr5", "value3"));

            e1.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr6", "value1"));
            e2.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr6", "value2"));
            e2.Attributes.Add(new NaiveXPathBuilder.NaiveXPathAttribute("attr6", "value3"));

            // Résultats:

            XPathElement output = NaiveXPathBuilder.NaiveXPathElement.Intersection(e1, e2);

            Assert.IsNotNull(output);
            Assert.IsInstanceOfType(output, typeof(NaiveXPathBuilder.NaiveXPathElement));

            XPathAttribute attr1 = output.Attributes.Find("attr1");

            Assert.IsNotNull(attr1);
            Assert.AreEqual("attr1", attr1.Name);
            Assert.AreEqual("value", attr1.Value);

            XPathAttribute attr2 = output.Attributes.Find("attr2");

            Assert.IsNotNull(attr2);
            Assert.AreEqual("attr2", attr2.Name);
            Assert.IsNull(attr2.Value);

            XPathAttribute attr3 = output.Attributes.Find("attr3");

            Assert.IsNull(attr3);

            XPathAttribute attr4 = output.Attributes.Find("attr4");

            Assert.IsNull(attr4);

            XPathAttribute attr5 = output.Attributes.Find("attr5");

            Assert.IsNull(attr5);

            XPathAttribute attr6 = output.Attributes.Find("attr6");

            Assert.IsNull(attr6);
        }
예제 #2
0
 public IQueryable ExecuteWhere(XPathElement element)
 {
     throw new NotImplementedException();
 }
예제 #3
0
        public Processor.OutputResult RecordDone(RecordBuilder record)
        {
            Debug.Assert(record != null);

            BuilderInfo mainNode = record.MainNode;

            documentIndex++;
            mainNode.LocalName    = doc.nt.Add(mainNode.LocalName);
            mainNode.NamespaceURI = doc.nt.Add(mainNode.NamespaceURI);
            switch (mainNode.NodeType)
            {
            case XmlNodeType.Element: {
                XPathElement e = mainNode.IsEmptyTag ?
                                 new XPathEmptyElement(mainNode.Prefix, mainNode.LocalName, mainNode.NamespaceURI, 0, 0, node.topNamespace, documentIndex) :
                                 new XPathElement(mainNode.Prefix, mainNode.LocalName, mainNode.NamespaceURI, 0, 0, node.topNamespace, documentIndex)
                ;
                node.AppendChild(e);

                XPathNamespace last = null;
                for (int attrib = 0; attrib < record.AttributeCount; attrib++)
                {
                    documentIndex++;
                    Debug.Assert(record.AttributeList[attrib] is BuilderInfo);
                    BuilderInfo attrInfo = (BuilderInfo)record.AttributeList[attrib];
                    if (attrInfo.NamespaceURI == Keywords.s_XmlnsNamespace)
                    {
                        XPathNamespace tmp = new XPathNamespace(attrInfo.Prefix == string.Empty ? string.Empty : attrInfo.LocalName, attrInfo.Value, documentIndex);
                        tmp.next = last;
                        last     = tmp;
                    }
                    else
                    {
                        e.AppendAttribute(new XPathAttribute(attrInfo.Prefix, attrInfo.LocalName, attrInfo.NamespaceURI, attrInfo.Value, documentIndex));
                    }
                }

                if (last != null)
                {
                    e.AppendNamespaces(last);
                }

                if (!mainNode.IsEmptyTag)
                {
                    node = e;
                }
                break;
            }

            case XmlNodeType.Text:
            case XmlNodeType.Whitespace:
            case XmlNodeType.SignificantWhitespace:
                node.AppendChild(new XPathText(mainNode.Value, 0, 0, documentIndex));
                break;

            case XmlNodeType.ProcessingInstruction:
                node.AppendChild(new XPathProcessingInstruction(mainNode.LocalName, mainNode.Value, documentIndex));
                break;

            case XmlNodeType.Comment:
                node.AppendChild(new XPathComment(mainNode.Value, documentIndex));
                break;

            case XmlNodeType.Document:
                break;

            case XmlNodeType.EndElement:
                node = node.parent;
                break;

            default:
                Debug.Fail("Invalid NodeType on output: " + mainNode.NodeType.ToString());
                break;
            }

            record.Reset();
            return(Processor.OutputResult.Continue);
        }