Ejemplo n.º 1
0
 public void TestCommentAndDocType()
 {
     string xml = "<!DOCTYPE html><!-- a comment -->One <qux />Two";
     XmlTreeBuilder tb = new XmlTreeBuilder();
     Document doc = tb.Parse(xml, "http://foo.com/");
     Assert.AreEqual("<!DOCTYPE html><!-- a comment -->One <qux />Two",
             TextUtil.StripNewlines(doc.Html));
 }
Ejemplo n.º 2
0
 public 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/");
     Assert.AreEqual("<doc><val>One<val>Two</val>Three</val></doc>",
             TextUtil.StripNewlines(doc.Html));
 }
Ejemplo n.º 3
0
 public 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/");
     Assert.AreEqual("<doc id=\"2\" href=\"/bar\">Foo <br /><link>One</link><link>Two</link></doc>",
             TextUtil.StripNewlines(doc.Html));
     Assert.AreEqual(doc.GetElementById("2").AbsUrl("href"), "http://foo.com/bar");
 }
Ejemplo n.º 4
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 IReadOnlyList<Node> ParseXmlFragment(string fragmentXml, string baseUri)
 {
     XmlTreeBuilder treeBuilder = new XmlTreeBuilder();
     return treeBuilder.ParseFragment(fragmentXml, baseUri, ParseErrorList.NoTracking());
 }
Ejemplo n.º 5
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 IReadOnlyList <Node> ParseXmlFragment(string fragmentXml, string baseUri)
        {
            XmlTreeBuilder treeBuilder = new XmlTreeBuilder();

            return(treeBuilder.ParseFragment(fragmentXml, baseUri, ParseErrorList.NoTracking()));
        }