当前位置: 首页>>代码示例>>Java>>正文


Java Xsoup.convertDocument方法代码示例

本文整理汇总了Java中us.codecraft.xsoup.Xsoup.convertDocument方法的典型用法代码示例。如果您正苦于以下问题:Java Xsoup.convertDocument方法的具体用法?Java Xsoup.convertDocument怎么用?Java Xsoup.convertDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在us.codecraft.xsoup.Xsoup的用法示例。


在下文中一共展示了Xsoup.convertDocument方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testByAttribute

import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testByAttribute() throws XPathExpressionException {

    org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));

    assertThat(getNodeValue(document, "//a[@href]")).isEqualTo("<a href=\"https://github.com\">github.com</a>");

    assertThat(getNodeValue(document, "//a[@id]")).isNull();

    String expectedDiv = "<div id=\"test\">\n" +
            " aaa\n" +
            " <div>\n" +
            "  <a href=\"https://github.com\">github.com</a>\n" +
            " </div>\n" +
            "</div>";


    //TODO: illegal
    //assertThat(getNodeValue(document,"//div[@id=test]")).isEqualTo(expectedDiv);

    assertThat(getNodeValue(document, "//div[@id='test']")).isEqualTo(expectedDiv);
    assertThat(getNodeValue(document, "//div[@id=\"test\"]")).isEqualTo(expectedDiv);
}
 
开发者ID:code4craft,项目名称:xsoup,代码行数:24,代码来源:W3cEvaluatorTest.java

示例2: testNth

import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testNth() throws XPathExpressionException {

    org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(htmlClass));

    assertThat(getNodeValue(document, "//body/div[1]")).isEqualTo("<div class=\"a b c\">\n" +
            " <div>\n" +
            "  <a href=\"https://github.com\">github.com</a>\n" +
            " </div>\n" +
            "</div>");

    assertThat(getNodeValue(document, "//body/div[2]")).isEqualTo("<div>\n" +
            " b\n" +
            "</div>");

    String htmlSVG = "<div><svg>1</svg><svg>2</svg></div>";

    document = Xsoup.convertDocument(Jsoup.parse(htmlSVG));
    assertThat(getNodeValue(document, "//div/svg[1]")).isEqualTo("<svg>\n" +
            " 1\n" +
            "</svg>");
    assertThat(getNodeValue(document, "//div/svg[2]")).isEqualTo("<svg>\n" +
            " 2\n" +
            "</svg>");
}
 
开发者ID:code4craft,项目名称:xsoup,代码行数:26,代码来源:W3cEvaluatorTest.java

示例3: testSelect

import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testSelect() throws XPathExpressionException {

    String html = "<html><div><a href='https://github.com'>github.com</a></div>" +
            "<table><tr><td>a</td><td>b</td></tr></table></html>";

    org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));

    assertThat(getStringValue(document, "//div/a/@href")).isEqualTo("https://github.com");

    List<String> nodeListValue = getNodeListValue(document, "//tr/td");
    assertThat(nodeListValue.get(0)).isEqualTo("<td>a</td>");
    assertThat(nodeListValue.get(1)).isEqualTo("<td>b</td>");
}
 
开发者ID:code4craft,项目名称:xsoup,代码行数:15,代码来源:W3cEvaluatorTest.java

示例4: testContains

import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testContains() throws XPathExpressionException {

    org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));

    assertThat(getNodeValue(document,"//div[contains(@id,'te')]")).isEqualTo("<div id=\"test\">\n" +
            " aaa\n" +
            " <div>\n" +
            "  <a href=\"https://github.com\">github.com</a>\n" +
            " </div>\n" +
            "</div>");

}
 
开发者ID:code4craft,项目名称:xsoup,代码行数:14,代码来源:W3cEvaluatorTest.java

示例5: testClass

import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testClass() throws XPathExpressionException {

    org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(htmlClass));


    assertThat(getNodeListValue(document,"//div[@class='a b c']").get(0)).isEqualTo("<div class=\"a b c\">\n" +
            " <div>\n" +
            "  <a href=\"https://github.com\">github.com</a>\n" +
            " </div>\n" +
            "</div>");

    assertThat(getNodeListValue(document, "//div[@class='b']")).isNullOrEmpty();

    assertThat(getNodeListValue(document, "//div[@class='d']")).isNullOrEmpty();


}
 
开发者ID:code4craft,项目名称:xsoup,代码行数:19,代码来源:W3cEvaluatorTest.java

示例6: testAttribute

import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testAttribute() throws XPathExpressionException {

    org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(htmlClass));

    assertThat(getStringValue(document,"//a/@href")).isEqualTo("https://github.com");

    //TODO:  not support
    //assertThat(getStringValue(document,"//a/text()")).isEqualTo("github.com");

    //TODO:  not support
    //assertThat(getStringValue(document,"//div[@class=a]/html()")).isEqualTo("<div>\n" +
    //        " <a href=\"https://github.com\">github.com</a>\n" +
    //        "</div>");

}
 
开发者ID:code4craft,项目名称:xsoup,代码行数:17,代码来源:W3cEvaluatorTest.java

示例7: testLogicOperation

import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testLogicOperation() throws XPathExpressionException {

    org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));

    String expectedDiv = "<div id=\"test\">\n" +
            " aaa\n" +
            " <div>\n" +
            "  <a href=\"https://github.com\">github.com</a>\n" +
            " </div>\n" +
            "</div>";

    assertThat(getNodeValue(document, "//*[@id='te' or @id='test']")).isEqualTo(expectedDiv);

    assertThat(getNodeValue(document, "//*[@id='te' and @id='test']")).isNullOrEmpty();

    assertThat(getNodeValue(document, "//*[@id='te' and @id='test']")).isNullOrEmpty();

    assertThat(getNodeValue(document,"//*[(@id='te' or @id='test') and @id='test']")).isEqualTo(expectedDiv);

    assertThat(getNodeValue(document,"//*[@id='te' or (@id='test' and @id='id')]")).isNull();
}
 
开发者ID:code4craft,项目名称:xsoup,代码行数:23,代码来源:W3cEvaluatorTest.java

示例8: testParent

import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testParent() throws XPathExpressionException {

    org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));

    assertThat(getNodeValue(document, "/html/body/div/div/a")).isEqualTo("<a href=\"https://github.com\">github.com</a>");
    assertThat(getNodeValue(document, "/html//div/div/a")).isEqualTo("<a href=\"https://github.com\">github.com</a>");

    assertThat(getNodeValue(document, "/html/div/div/a")).isNull();

}
 
开发者ID:code4craft,项目名称:xsoup,代码行数:12,代码来源:W3cEvaluatorTest.java

示例9: testCombingXPath

import us.codecraft.xsoup.Xsoup; //导入方法依赖的package包/类
@Test
public void testCombingXPath() throws XPathExpressionException {

    String html2 = "<html><div id='test2'>aa<a href='https://github.com'>github.com</a></div>";

    String expectedDiv1 = "<div id=\"test\">\n" +
            " aaa\n" +
            " <div>\n" +
            "  <a href=\"https://github.com\">github.com</a>\n" +
            " </div>\n" +
            "</div>";

    String expectedDiv2 = "<div id=\"test2\">\n" +
            " aa\n" +
            " <a href=\"https://github.com\">github.com</a>\n" +
            "</div>";

    org.w3c.dom.Document document = Xsoup.convertDocument(Jsoup.parse(html));

    assertThat(getNodeValue(document, "//div[@id='test'] | //div[@id='test2']")).isEqualTo(expectedDiv1);

    document = Xsoup.convertDocument(Jsoup.parse(html2));

    assertThat(getNodeValue(document, "//div[@id='test'] | //div[@id='test2']")).isEqualTo(expectedDiv2);

    document = Xsoup.convertDocument(Jsoup.parse(html+html2));

    assertThat(getNodeListValue(document, "//div[@id='test'] | //div[@id='test2']")).contains(expectedDiv1,expectedDiv2);

}
 
开发者ID:code4craft,项目名称:xsoup,代码行数:31,代码来源:W3cEvaluatorTest.java


注:本文中的us.codecraft.xsoup.Xsoup.convertDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。