0
我想用屬性和值解析這個XML。現在我能夠解析值,但我無法解析屬性。解析帶屬性的XML
我的XML:
<Book>
<vendor>
<vendorPartyReference href="VENDOR"/>
<vendorDefinedValue fieldName="Bookuser">dav</vendorDefinedValue>
<vendorDefinedValue fieldName="ComUser">dav</vendorDefinedValue>
<vendorDefinedValue fieldName="Rate">1.02505</vendorDefinedValue>
<vendorDefinedValue fieldName="Points">0.00000</vendorDefinedValue>
<vendorDefinedValue fieldName="Design">DSF</vendorDefinedValue>
<vendorDefinedValue fieldName="Role">APPROVER</vendorDefinedValue>
<vendorDefinedValue fieldName="cover">DXBook12</vendorDefinedValue>
<vendorDefinedValue fieldName="Organization">Mannar</vendorDefinedValue>
</vendor>
</Book>
我想分析像字段名作爲鍵和值DAV(值)。
NodeList nList = document.getElementsByTagName("Book");
for(int s=0; s<nList.getLength() ; s++)
{
NodeList tsfpmlVendor = document.getElementsByTagName("vendor");
for(int i=0; i<tsfpmlVendor.getLength(); i++)
{
Node tsfpmlVendorNode = tsfpmlVendor.item(i);
Element tsfpmlVendorElement = (Element)tsfpmlVendorNode;
for(int j=0; j<tsfpmlVendorElement.getElementsByTagName("vendorDefinedValue").getLength(); j++)
{
listVendorField.add(tsfpmlVendorElement.getElementsByTagName("vendorDefinedValue").item(j).getTextContent());
System.out.println("kkk: "+ tsfpmlVendorElement.getElementsByTagName("vendorDefinedValue").item(j).getAttributes().getLength());
System.out.println("kkk: "+ tsfpmlVendorElement.getElementsByTagName("vendorDefinedValue").item(j).getNodeType());
}
}
}