com.ximpleware解析XML - XPath - 在==>结束之后或之前的语法错误

时间:2016-04-05 07:45:33

标签: java xml parsing xpath vtd-xml

我使用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? 谢谢!

1 个答案:

答案 0 :(得分:2)

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

selectXPath()