Java 使用Xpath进行属性提取
我有一个XML作为Java字符串:Java 使用Xpath进行属性提取,java,xml,xpath,Java,Xml,Xpath,我有一个XML作为Java字符串: String abc = "<Tags Value = '635' Type = 'Number'/>"; 试试看 公共类示例{ 公共静态void main(字符串[]args)抛出FileNotFoundException、XPathExpressionException{ 字符串abc=“”; InputSource文档=新的InputSource(新的StringReader(abc)); XPath=XPathFactory.newIn
String abc = "<Tags Value = '635' Type = 'Number'/>";
试试看
公共类示例{
公共静态void main(字符串[]args)抛出FileNotFoundException、XPathExpressionException{
字符串abc=“”;
InputSource文档=新的InputSource(新的StringReader(abc));
XPath=XPathFactory.newInstance().newXPath();
XPathExpression expr=xPath.compile(“/Tags/@Value”);
System.out.println(expr.evaluate(doc));//635
}
}
试试看
public class Example {
public static void main(String[] args) throws FileNotFoundException, XPathExpressionException {
String abc = "<Tags Value = '635' Type = 'Number'/>";
InputSource doc = new InputSource(new StringReader(abc));
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xPath.compile("/Tags/@Value");
System.out.println(expr.evaluate(doc)); // 635
}
}
公共类示例{
公共静态void main(字符串[]args)抛出FileNotFoundException、XPathExpressionException{
字符串abc=“”;
InputSource文档=新的InputSource(新的StringReader(abc));
XPath=XPathFactory.newInstance().newXPath();
XPathExpression expr=xPath.compile(“/Tags/@Value”);
System.out.println(expr.evaluate(doc));//635
}
}
线程“main”java.net.MalformedURLException:无协议:/Tags/@Value]
是否仔细检查了该语法?线程“main”java.net.MalformedURLException:无协议:/Tags/@Value]
是否仔细检查了该语法?
InputSource doc = new InputSource(abc);
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xPath.compile("/Tags/@Value");
System.out.println(expr.evaluate(doc));
public class Example {
public static void main(String[] args) throws FileNotFoundException, XPathExpressionException {
String abc = "<Tags Value = '635' Type = 'Number'/>";
InputSource doc = new InputSource(new StringReader(abc));
XPath xPath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xPath.compile("/Tags/@Value");
System.out.println(expr.evaluate(doc)); // 635
}
}