Java: how to parse an html string for XML tool consume? -
which library allow me evaluate xpath on html string ?
i have tried using javax package seems fail:
string docroot = "<div><i>items <b>sold</b></i></div>"; xpath xxpath = xpathfactory.newinstance().newxpath(); inputsource docroot = new inputsource(new stringreader(subelements)); string result = (string) xxpath.evaluate("//b", docroot, xpathconstants.string);
try following instead, there errors in code sample:
import java.io.stringreader; import javax.xml.xpath.xpath; import javax.xml.xpath.xpathconstants; import javax.xml.xpath.xpathfactory; import org.xml.sax.inputsource; public class demo { public static void main(string[] args) throws exception { string docroot = "<div><i>items <b>sold</b></i></div>"; xpath xxpath = xpathfactory.newinstance().newxpath(); inputsource inputsource = new inputsource(new stringreader(docroot)); string result = (string) xxpath.evaluate("//b", inputsource, xpathconstants.string); system.out.println(result); } }
Comments
Post a Comment