gpt4 book ai didi

java - 使用java代码在xpath中标记化

转载 作者:行者123 更新时间:2023-12-02 04:37:11 24 4
gpt4 key购买 nike

有没有办法从 xpath 获取 tokenize 值。

尝试过但没有帮助。String Xpath="tokenize(/root/child, '~')[1]";

getAttributeValue(元素,Xpath);

public static String getAttributeValue(Element obj, String xpath) throws Exception{


XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpatha = xPathfactory.newXPath();
XPathExpression expr = xpatha.compile(xpath);
String value =(String) expr.evaluate(obj, XPathConstants.STRING);


return value;

}

<root>
<child>hello~How~Are~You</child></root>

我需要来自 xpath 的“How”第二个 token 。我怎样才能得到这个

最佳答案

您需要使用 XPath 2.0 或 3.0 或 XQuery 1.0 或更高版本的实现(如 tokenize 于 2007 年在 XPath 2.0 或 XQuery 1.0 中引入)以及一个合适的 API,该 API 允许您返回XPath 2.0 或 XQuery 1.0 处理的值。

例如,使用 Saxon 9.6 和 XPath 2.0 我建议使用 http://saxonica.com/html/documentation/xpath-api/s9api-xpath.html .

关于java - 使用java代码在xpath中标记化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30614437/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com