Exemplo n.º 1
0
        /// <summary>Parse a fragment of XML into a list of nodes.</summary>
        /// <param name="fragmentXml">the fragment of XML to parse</param>
        /// <param name="baseUri">base URI of document (i.e. original fetch location), for resolving relative URLs.</param>
        /// <returns>list of nodes parsed from the input XML.</returns>
        public static IList <iText.StyledXmlParser.Jsoup.Nodes.Node> ParseXmlFragment(String fragmentXml, String baseUri
                                                                                      )
        {
            XmlTreeBuilder treeBuilder = new XmlTreeBuilder();

            return(treeBuilder.ParseFragment(fragmentXml, baseUri, ParseErrorList.NoTracking()));
        }
Exemplo n.º 2
0
        public virtual void TestCommentAndDocType()
        {
            String         xml = "<!DOCTYPE html><!-- a comment -->One <qux />Two";
            XmlTreeBuilder tb  = new XmlTreeBuilder();
            Document       doc = tb.Parse(xml, "http://foo.com/");

            NUnit.Framework.Assert.AreEqual("<!DOCTYPE html><!-- a comment -->One <qux />Two", TextUtil.StripNewlines(
                                                doc.Html()));
        }
Exemplo n.º 3
0
        public virtual void TestPopToClose()
        {
            // test: </val> closes Two, </bar> ignored
            String         xml = "<doc><val>One<val>Two</val></bar>Three</doc>";
            XmlTreeBuilder tb  = new XmlTreeBuilder();
            Document       doc = tb.Parse(xml, "http://foo.com/");

            NUnit.Framework.Assert.AreEqual("<doc><val>One<val>Two</val>Three</val></doc>", TextUtil.StripNewlines(doc
                                                                                                                   .Html()));
        }
Exemplo n.º 4
0
        public virtual void TestSimpleXmlParse()
        {
            String         xml = "<doc id=2 href='/bar'>Foo <br /><link>One</link><link>Two</link></doc>";
            XmlTreeBuilder tb  = new XmlTreeBuilder();
            Document       doc = tb.Parse(xml, "http://foo.com/");

            NUnit.Framework.Assert.AreEqual("<doc id=\"2\" href=\"/bar\">Foo <br /><link>One</link><link>Two</link></doc>"
                                            , TextUtil.StripNewlines(doc.Html()));
            NUnit.Framework.Assert.AreEqual(doc.GetElementById("2").AbsUrl("href"), "http://foo.com/bar");
        }
Exemplo n.º 5
0
        /// <summary>Parse XML into a Document.</summary>
        /// <param name="xml">XML to parse</param>
        /// <param name="baseUri">base URI of document (i.e. original fetch location), for resolving relative URLs.</param>
        /// <returns>parsed Document</returns>
        public static Document ParseXml(String xml, String baseUri)
        {
            TreeBuilder treeBuilder = new XmlTreeBuilder();

            return(treeBuilder.Parse(xml, baseUri, ParseErrorList.NoTracking()));
        }