com.ximpleware 解析 XML - XPath - 在 ==> 结束后或附近出现语法错误

com.ximpleware parse XML - XPath - Syntax error after or around the end of ==>

我使用 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);
.....