示例#1
0
        public void NetHyperElementJoinOneToOnePred()
        {
            XmlDocument doc;
            bool        created = CreateAndInitDom(out doc);

            if (created)
            {
                Element root = new Element();
                root.SetDomDoc(doc);

                Element elem1 = root["aa|bb|cc"].CreateNew(null);
                elem1.SetInt32(11);
                Element elem2 = root["aa|bb|cc"].CreateNew(null);
                elem2.SetInt32(22);
                Element elem3 = root["aa|bb|cc"].CreateNew(null);
                elem3.SetInt32(33);

                Element elem4 = root["dd|ee"].CreateNew(null);
                elem4.Attr("SomeValue").SetInt32(11);
                Element elem5 = root["dd|ee"].CreateNew(null);
                elem5.Attr("SomeValue").SetInt32(22);
                Element elem6 = root["dd|ee"].CreateNew(null);
                elem6.Attr("SomeValue").SetInt32(33);

                List <KeyValuePair <Elmax.Element, Elmax.Element> > vec =
                    HyperElement.JoinOneToOne(elem1.AsCollection(), elem4.AsCollection(), (x, y) => x.GetInt32(0) == y.Attr("SomeValue").GetInt32(1));

                Assert.AreEqual(vec.Count, 3);
                for (int i = 0; i < vec.Count; ++i)
                {
                    Assert.AreEqual(vec[i].Key.GetInt32(10), vec[i].Value.Attr("SomeValue").GetInt32(11));
                }

                XmlDocument doc2;
                Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


                Element root2 = new Element();
                root2.SetDomDoc(doc2);

                List <KeyValuePair <Elmax.Element, Elmax.Element> > vec2 =
                    HyperElement.JoinOneToOne(
                        root2["aa|bb|cc"].AsCollection(),
                        root2["dd|ee"].AsCollection(),
                        (x, y) => x.GetInt32(0) == y.Attr("SomeValue").GetInt32(1));

                Assert.AreEqual(vec2.Count, 3);
                for (int i = 0; i < vec2.Count; ++i)
                {
                    Assert.AreEqual(vec2[i].Key.GetInt32(10), vec2[i].Value.Attr("SomeValue").GetInt32(11));
                }
            }
        }
示例#2
0
        private void TestRead()
        {
            XmlDocument doc;
            string      strFilename = "Books.xml";
            bool        b           = CreateAndLoadXml(out doc, strFilename);

            if (b)
            {
                Element root = new Element();
                root.SetDomDoc(doc);

                Element all = root["All"];
                if (all.Exists == false)
                {
                    Debug.Print("Error: root does not exists!");
                    return;
                }
                Debug.Print("Version : {0}\n", all["Version"].GetInt32(0));

                Debug.Print("Books");
                Debug.Print("=====");
                Element books = all["Books"];
                if (books.Exists)
                {
                    List <Element> listBooks = books.GetChildren("Book");
                    for (int i = 0; i < listBooks.Count; ++i)
                    {
                        Debug.Print("ISBN: {0}", listBooks[i].Attr("ISBN").GetString("Error: None"));
                        Debug.Print("Title: {0}", listBooks[i]["Title"].GetString("Error: No title!"));
                        Debug.Print("Price: {0}", listBooks[i]["Price"].GetFloat(0.0f));
                        Debug.Print("Desc: {0}", listBooks[i]["Desc"].GetString("Error: None"));
                        Debug.Print("AuthorID: {0}\n", listBooks[i]["AuthorID"].GetInt32(-1));
                    }
                }

                Debug.Print("Authors");
                Debug.Print("=======");
                Element authors = all["Authors"];
                if (authors.Exists)
                {
                    List <Element> listAuthors = authors.GetChildren("Author");
                    for (int i = 0; i < listAuthors.Count; ++i)
                    {
                        Debug.Print("Name: {0}", listAuthors[i].Attr("Name").GetString("Error: None"));
                        Debug.Print("AuthorID: {0}", listAuthors[i].Attr("AuthorID").GetInt32(-1));
                        Debug.Print("Bio: {0}\n", listAuthors[i]["Bio"].GetString("Error: No bio!"));
                    }
                }

                var vec = HyperElement.JoinOneToMany(authors.GetChildren("Author"), books.GetChildren("Book"),
                                                     (x, y) => x.Attr("AuthorID").GetString("a") == y["AuthorID"].GetString("a"));

                for (int i = 0; i < vec.Count; ++i)
                {
                    Debug.Print("List of books by {0}", vec[i].Key.Attr("Name").GetString(""));
                    Debug.Print("=============================================");
                    for (int j = 0; j < vec[i].Value.Count; ++j)
                    {
                        Debug.Print("{0}", vec[i].Value[j]["Title"].GetString("None"));
                    }
                    Debug.Print("");
                }
            }
            //DeleteFile(strFilename);
        }
示例#3
0
        public void NetHyperElementJoinOneToMany()
        {
            XmlDocument doc;
            bool        created = CreateAndInitDom(out doc);

            if (created)
            {
                Element root = new Element();
                root.SetDomDoc(doc);

                Element elem1 = root["aa|bb|cc"].CreateNew(null);
                elem1.SetInt32(11);
                Element elem2 = root["aa|bb|cc"].CreateNew(null);
                elem2.SetInt32(22);
                Element elem3 = root["aa|bb|cc"].CreateNew(null);
                elem3.SetInt32(33);

                Element elem4 = root["dd|ee"].CreateNew(null);
                elem4.Attr("SomeValue").SetInt32(11);
                Element elem5 = root["dd|ee"].CreateNew(null);
                elem5.Attr("SomeValue").SetInt32(22);
                Element elem6 = root["dd|ee"].CreateNew(null);
                elem6.Attr("SomeValue").SetInt32(33);
                Element elem7 = root["dd|ee"].CreateNew(null);
                elem7.Attr("SomeValue").SetInt32(11);
                Element elem8 = root["dd|ee"].CreateNew(null);
                elem8.Attr("SomeValue").SetInt32(22);
                Element elem9 = root["dd|ee"].CreateNew(null);
                elem9.Attr("SomeValue").SetInt32(33);
                Element elem10 = root["dd|ee"].CreateNew(null);
                elem10.Attr("SomeValue").SetInt32(11);
                Element elem11 = root["dd|ee"].CreateNew(null);
                elem11.Attr("SomeValue").SetInt32(22);
                Element elem12 = root["dd|ee"].CreateNew(null);
                elem12.Attr("SomeValue").SetInt32(33);

                List <KeyValuePair <Elmax.Element, List <Elmax.Element> > > vec =
                    HyperElement.JoinOneToMany(elem1.AsCollection(), "", elem4.AsCollection(), "SomeValue", false);

                Assert.AreEqual(vec.Count, 3);
                for (int i = 0; i < vec.Count; ++i)
                {
                    Assert.AreEqual(vec[i].Value.Count, 3);
                }

                XmlDocument doc2;
                Assert.IsTrue(CreateAndLoadXmlString(out doc2, doc.OuterXml));


                Element root2 = new Element();
                root2.SetDomDoc(doc2);

                List <KeyValuePair <Elmax.Element, List <Elmax.Element> > > vec2 =
                    HyperElement.JoinOneToMany(root2["aa|bb|cc"].AsCollection(), "", root2["dd|ee"].AsCollection(), "SomeValue", false);

                Assert.AreEqual(vec2.Count, 3);
                for (int i = 0; i < vec2.Count; ++i)
                {
                    Assert.AreEqual(vec2[i].Value.Count, 3);
                }
            }
        }