simplify api
parent
d7899e94ae
commit
7f27c28d4c
|
@ -1384,18 +1384,14 @@ public class XpathSelectorTest {
|
||||||
public void testSaxon() throws XPathFactoryConfigurationException {
|
public void testSaxon() throws XPathFactoryConfigurationException {
|
||||||
System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_SAXON, "net.sf.saxon.xpath.XPathFactoryImpl");
|
System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_SAXON, "net.sf.saxon.xpath.XPathFactoryImpl");
|
||||||
System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.FN, "net.sf.saxon.xpath.XPathFactoryImpl");
|
System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.FN, "net.sf.saxon.xpath.XPathFactoryImpl");
|
||||||
XPathFactory xpf = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
|
|
||||||
String text = "<h1>眉山:扎实推进农业农村工作 促农持续增收<br>\n" +
|
String text = "<h1>眉山:扎实推进农业农村工作 促农持续增收<br>\n" +
|
||||||
"<span>2013-07-31 23:29:45 来源:<a href=\"http://www.mshw.net\" target=\"_blank\" style=\"color:#AAA\">眉山网</a> 责任编辑:张斯炜</span></h1>";
|
"<span>2013-07-31 23:29:45 来源:<a href=\"http://www.mshw.net\" target=\"_blank\" style=\"color:#AAA\">眉山网</a> 责任编辑:张斯炜</span></h1>";
|
||||||
try {
|
try {
|
||||||
HtmlCleaner htmlCleaner = new HtmlCleaner();
|
HtmlCleaner htmlCleaner = new HtmlCleaner();
|
||||||
TagNode tagNode = htmlCleaner.clean(text);
|
TagNode tagNode = htmlCleaner.clean(text);
|
||||||
Document document = new DomSerializer(new CleanerProperties()).createDOM(tagNode);
|
Document document = new DomSerializer(new CleanerProperties()).createDOM(tagNode);
|
||||||
javax.xml.xpath.XPathFactory factory = XPathFactoryImpl.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
|
XPathEvaluator xPathEvaluator = new XPathEvaluator();
|
||||||
Configuration config = Configuration.newConfiguration();
|
xPathEvaluator.setNamespaceContext(new NamespaceContextImpl(new NamespaceResolver() {
|
||||||
XPathEvaluator xPathEvaluator = new XPathEvaluator(config);
|
|
||||||
JAXPXPathStaticContext context = new JAXPXPathStaticContext(config);
|
|
||||||
context.setNamespaceContext(new NamespaceContextImpl(new NamespaceResolver() {
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1408,7 +1404,6 @@ public class XpathSelectorTest {
|
||||||
return Collections.singletonList("fn").iterator();
|
return Collections.singletonList("fn").iterator();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
xPathEvaluator.setStaticContext(context);
|
|
||||||
XPathExpression expr = xPathEvaluator.compile("fn:substring-before(//h1,'\n')");
|
XPathExpression expr = xPathEvaluator.compile("fn:substring-before(//h1,'\n')");
|
||||||
Object result = expr.evaluate(document, XPathConstants.STRING);
|
Object result = expr.evaluate(document, XPathConstants.STRING);
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
|
|
Loading…
Reference in New Issue