如何将字符串xml中的节点再次作为字符串

时间:2012-09-25 08:50:29

标签: java xml

我将XML作为字符串,并且此XML字符串具有多个节点:例如4 billingDetail节点。如何解析字符串并再次将4个节点作为字符串输出?

我正在使用JAVA。我尝试使用马歇尔然后解组但是速度慢而且工作不正常

示例:

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

2 个答案:

答案 0 :(得分:1)

检查此链接

http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/

它清楚地指导您满足您的需求!

答案 1 :(得分:0)

完成此

对于DOM-Parser: - http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/

对于SAX-Parse: - http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/

它将帮助您更好地理解并以简单的方式获取节点