1

これは私のxmlです:

例:

<?xml version="1.0" encoding="UTF_8" standalone="yes"?>
<StoreMessage xmlns="http://www.xxx.com/feed">
    <billingDetail>
        <billingDetailId>987</billingDetailId>       
        <contextId>0</contextId>
        <userId>
            <pan>F0F8DJH348DJ</pan>
            <contractSerialNumber>46446</contractSerialNumber>            
        </userId>            
        <declaredVehicleClass>A</declaredVehicleClass>
    </billingDetail>
    <billingDetail>
        <billingDetailId>543</billingDetailId>       
        <contextId>0</contextId>
        <userId>
            <pan>F0F854534534348DJ</pan>
            <contractSerialNumber>4666546446</contractSerialNumber>            
        </userId>            
        <declaredVehicleClass>C</declaredVehicleClass>
    </billingDetail>
</StoreMessage>

JDOM パーサーを使用し<billingDetail>て、そこからすべての xml ノードを取得したいと考えています。

私のコード:

SAXBuilder builder = new SAXBuilder();
try {
    Reader in = new StringReader(xmlAsString);
    Document document = (Document)builder.build(in);
    Element rootNode = document.getRootElement();
    List<?> list = rootNode.getChildren("billingDetail");

    XMLOutputter outp = new XMLOutputter();
        outp.setFormat(Format.getCompactFormat());

        for (int i = 0; i < list.size(); i++) {

            Element node = (Element)list.get(i);

            StringWriter sw = new StringWriter();
            outp.output(node.getContent(), sw);
            StringBuffer sb = sw.getBuffer();

            String text = sb.toString();
            xmlRecords.add(sb.toString());
        }

} catch (IOException io) {
    io.printStackTrace();
} catch (JDOMException jdomex) {
    jdomex.printStackTrace();
}

しかし、次のような文字列としてxmlノードを出力することはありません。

<billingDetail>
    <billingDetailId>987</billingDetailId>       
    <contextId>0</contextId>
    <userId>
        <pan>F0F8DJH348DJ</pan>
        <contractSerialNumber>46446</contractSerialNumber>            
    </userId>            
    <declaredVehicleClass>A</declaredVehicleClass>
</billingDetail>

私は何を間違っていますか?JDOMパーサーでこの出力を取得するにはどうすればよいですか?

編集

XML が

<StoreMessage>代わりに<StoreMessage xmlns="http://www.xxx.com/MediationFeed">

その後動作しますか?これはどのように可能ですか?

4

1 に答える 1