From 7f27c28d4c43d3d0d285d9c997c676659a55f916 Mon Sep 17 00:00:00 2001 From: "yihua.huang" Date: Fri, 2 Aug 2013 23:45:13 +0800 Subject: [PATCH] simplify api --- .../codecraft/webmagic/selector/XpathSelectorTest.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/webmagic-core/src/test/java/us/codecraft/webmagic/selector/XpathSelectorTest.java b/webmagic-core/src/test/java/us/codecraft/webmagic/selector/XpathSelectorTest.java index c2cc7ec..6544e9e 100644 --- a/webmagic-core/src/test/java/us/codecraft/webmagic/selector/XpathSelectorTest.java +++ b/webmagic-core/src/test/java/us/codecraft/webmagic/selector/XpathSelectorTest.java @@ -1384,18 +1384,14 @@ public class XpathSelectorTest { 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.FN, "net.sf.saxon.xpath.XPathFactoryImpl"); - XPathFactory xpf = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON); String text = "

眉山:扎实推进农业农村工作 促农持续增收
\n" + "2013-07-31 23:29:45   来源:眉山网      责任编辑:张斯炜

"; try { HtmlCleaner htmlCleaner = new HtmlCleaner(); TagNode tagNode = htmlCleaner.clean(text); Document document = new DomSerializer(new CleanerProperties()).createDOM(tagNode); - javax.xml.xpath.XPathFactory factory = XPathFactoryImpl.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON); - Configuration config = Configuration.newConfiguration(); - XPathEvaluator xPathEvaluator = new XPathEvaluator(config); - JAXPXPathStaticContext context = new JAXPXPathStaticContext(config); - context.setNamespaceContext(new NamespaceContextImpl(new NamespaceResolver() { + XPathEvaluator xPathEvaluator = new XPathEvaluator(); + xPathEvaluator.setNamespaceContext(new NamespaceContextImpl(new NamespaceResolver() { @Override @@ -1408,7 +1404,6 @@ public class XpathSelectorTest { return Collections.singletonList("fn").iterator(); } })); - xPathEvaluator.setStaticContext(context); XPathExpression expr = xPathEvaluator.compile("fn:substring-before(//h1,'\n')"); Object result = expr.evaluate(document, XPathConstants.STRING); System.out.println(result);