3
私はXPath(JAXP)でTagSoupを使用しようとしています。私はTagSoup(またはXMLReader)からSAXパーサを取得する方法を知っています。しかし、私はそのSAXパーサを使用するDocumentBuilderの作成方法を見つけることができませんでした。それ、どうやったら出来るの?TagSoupとXPath
ありがとうございます。
EDIT:とても一般的ですが、Java XML APIはあまりにも痛みです。
EDIT2:
問題が解決:
public static void main(String[] args) throws XPathExpressionException, IOException,
SAXNotRecognizedException, SAXNotSupportedException,
TransformerFactoryConfigurationError, TransformerException {
XPathFactory xpathFac = XPathFactory.newInstance();
XPath xpath = xpathFac.newXPath();
InputStream input = new FileInputStream("/tmp/g.html");
XMLReader reader = new Parser();
reader.setFeature(Parser.namespacesFeature, false);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
DOMResult result = new DOMResult();
transformer.transform(new SAXSource(reader, new InputSource(input)), result);
Node htmlNode = result.getNode();
NodeList nodes = (NodeList) xpath.evaluate("//span", htmlNode, XPathConstants.NODESET);
System.out.println(nodes.getLength());
}
EDIT3:私を助け
リンク:http://www.jezuk.co.uk/cgi-bin/view/jez?id=2643