gpt4 book ai didi

java - com.ximpleware 解析 XML - XPath - ==> 末尾或附近的语法错误

转载 作者:行者123 更新时间:2023-11-30 02:59:04 25 4
gpt4 key购买 nike

我使用 com.ximpleware 并尝试解析这样的 XML:

<S2SCTScf:SCTScfBlkCredTrf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:S2SCTScf="urn:S2SCTScf:xsd:$SCTScfBlkCredTrf" xsi:schemaLocation="urn:S2SCTScf:xsd:$SCTScfBlkCredTrf file:///T:/CommonData%201/CBS/CBS%20Payments%20Team/Testing/XSD/SCT/SCTScfBlkCredTrf.xsd">
<CdtTrfTxInf>
<PmtId>
<EndToEndId>171766 12856615</EndToEndId>
<TxId>6022064LAS99</TxId>
</PmtId>
..............
</CdtTrfTxInf>
..............
</S2SCTScf:SCTScfBlkCredTrf>

和java代码:

        VTDGen vg = new VTDGen();
if (vg.parseFile("aaa.xml",true)){
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
ap.bind(vn);
str = "/S2SCTScf:SCTScfBlkCredTrf/CdtTrfTxInf";
ap.selectXPath(str);
System.out.println(ap.evalXPath());
}

抛出一个错误:

 Syntax error after or around the end of ==>
Exception during navigation com.ximpleware.XPathParseException: No URL found for prefix:S2SCTScf

知道如果我无法修改 XML,我应该做什么?谢谢!

最佳答案

不熟悉vtd-xml,但文档建议您需要通过 declareXPathNameSpace() 注册命名空间前缀在 selectXPath() 中使用它之前:

.....
ap.declareXPathNameSpace("S2SCTScf", "urn:S2SCTScf:xsd:$SCTScfBlkCredTrf");
str = "/S2SCTScf:SCTScfBlkCredTrf/CdtTrfTxInf";
ap.selectXPath(str);
.....

关于java - com.ximpleware 解析 XML - XPath - ==> 末尾或附近的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36420112/

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