我正在尝试使用 JDOM 读取以下 XML 字符串响应,但不知道如何解析?你能帮我么?我正在尝试以下代码来解析:
org.jdom.Element rootNode = document.getRootElement();
List<?> list = rootNode.getChildren("QuotationResponse");
for(int i = 1 ; i <= list.size() ; i++) {
Element node = (Element) list.get(i);
String documentDate = node.getAttribute("documentDate");
String transactionType = node.getAttribute("transactionType");
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><VtEnvelope
xmlns="un:vtinc:o-series:tps:6:0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Login><UserName>user</UserName>
<Password>abcd</Password>
</Login>
<QuotationResponse documentDate="2011-03-24" transactionType="SALE"><Customer><Destination taxAreaId="1230000"><City>Dallas</City>
<MainDivision>TX</MainDivision>
<SubDivision>Chester</SubDivision>
<PostalCode>75038</PostalCode>
<Country>USA</Country>
</Destination>
</Customer>
<SubTotal>1000.0</SubTotal>
<Total>1060.0</Total>
<TotalTax>60.0</TotalTax>
<LineItem lineItemId="1" lineItemNumber="1" taxDate="2013-04-25"><Product productClass="product class attribute value">product code value</Product>
<Quantity>1.0</Quantity>
<FairMarketValue>1000.0</FairMarketValue>
<UnitPrice>1000.0</UnitPrice>
<ExtendedPrice>1000.0</ExtendedPrice>
<Taxes taxResult="TAXABLE" taxType="SALES" situs="DESTINATION" taxCollectedFromParty="BUYER"><Jurisdiction jurisdictionLevel="STATE" jurisdictionId="3051">Texas</Jurisdiction>
<CalculatedTax>60.0</CalculatedTax>
<EffectiveRate>0.06</EffectiveRate>
<Taxable>1000.0</Taxable>
<Imposition impositionType="General Sales and Use Tax">Sales and Use Tax</Imposition>
<TaxRuleId>121</TaxRuleId>
</Taxes>
<TotalTax>60.0</TotalTax>
</LineItem>
</QuotationResponse>
</VtEnvelope></S:Body></S:Envelope>