我想用属性和值解析这个 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(values)。
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());
}
}
}