Beispiel #1
0
        public void Reading()
        {
            Stream        stm = Globals.GetResource(Globals.PubsNsResource);
            XmlTextReader tr  = new XmlTextReader(stm);

            XPathDocument  doc = new XPathDocument(tr);
            XPathNavigator nav = doc.CreateNavigator();

            // Dumps the entire document to output.
            XmlTextWriter tw = new XmlTextWriter(Console.Out);

            tw.WriteNode(new XPathNavigatorReader(nav), true);

            // Perform a query, then dump the first node (OuterXml) from the result.
            nav = doc.CreateNavigator();
            XmlNamespaceManager mgr = new XmlNamespaceManager(nav.NameTable);

            mgr.AddNamespace("mvp", "mvp-xml");
            XPathNodeIterator it = XPathCache.Select("//mvp:titles[mvp:title_id='BU2075']", nav, mgr);

            if (it.MoveNext())
            {
                XmlReader title = new XPathNavigatorReader(it.Current);
                // As it's a regular reader, we must first move it to content as usual.
                title.MoveToContent();
                Console.WriteLine(title.ReadOuterXml());
            }

            // Perform arbitrary movements, then serialize inner content.
            nav = doc.CreateNavigator();
            nav.MoveToFirstChild();
            nav.MoveToFirstChild();
            Console.WriteLine(new XPathNavigatorReader(nav).ReadInnerXml());
        }
Beispiel #2
0
        public void TestRead()
        {
            XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.LibraryResource));

            //Navigator over first child of document element
            XPathNavigator nav = doc.CreateNavigator();

            nav.MoveToRoot();
            nav.MoveToFirstChild();
            nav.MoveToFirstChild();
            XPathNavigatorReader r = new XPathNavigatorReader(nav);

            r.MoveToContent();
            Console.WriteLine(r.ReadOuterXml());
        }
Beispiel #3
0
        public void MoveToContent()
        {
            string xml = @"<root><element>1</element><element></element><element>2</element></root>";

            XPathNavigator nav = new XPathDocument(new StringReader(xml)).CreateNavigator();

            XmlReader reader = new XPathNavigatorReader(nav);

            reader.MoveToContent();
            Console.WriteLine(reader.ReadOuterXml());

            reader = new XmlTextReader(new StringReader(xml));

            reader.MoveToContent();
            Console.WriteLine(reader.ReadOuterXml());
        }