我有一个xml,其中包含:
<BusinessEntity value="0">
<Name>
<Value locale="en">amd</Value>
</Name>
<UniqueFields>
<Field name="ID" value="0" />
</UniqueFields>
</BusinessEntity>
我正在使用stax解析器,但是当我在START_ELEMENT中设置BusinessEntity的布尔值然后我来到CHARACTERS时,xmlStreamReader.getText()返回为null。
性状:
case XMLStreamConstants.CHARACTERS:
//System.out.println(PriceName + " " + xmlStreamReader.getText().trim());
if(BusinessEntity){
// System.out.println(Value + " " + xmlStreamReader.getText().trim());
// XMLTag.setBusinessEntity(xmlStreamReader.getText().trim());
// System.out.println( "here " + xmlStreamReader.getText().trim() );
MapForTemp.put("BusinessEntity", xmlStreamReader.getText().trim());
BusinessEntity = false;
}
Start_ELEMENT:
if (xmlStreamReader.getLocalName().equals("BusinessEntity"))
{
BusinessEntity = true;
getAttributes(xmlStreamReader);
//int getAttribCount = xmlStreamReader .getAttributeCount();
}
getAttributes:
public static void getAttributes (XMLStreamReader xmlStreamReader){
int AttributeCount = xmlStreamReader.getAttributeCount();
if (xmlStreamReader.getLocalName().equalsIgnoreCase("Price"))
{
if (xmlStreamReader.getAttributeLocalName(0).equals("id")){
priceguid = (xmlStreamReader.getAttributeValue(0));
}
}
if (AttributeCount > 0)
{
StringBuilder stb = new StringBuilder();
for (int m = 0; m < AttributeCount; m++)
{
stb.append(priceguid + " : " + xmlStreamReader.getLocalName() + " : " + xmlStreamReader.getAttributeLocalName(m));
MapForAttributes.put(stb.toString().intern(), xmlStreamReader.getAttributeValue(m));
stb.setLength(0);
}
}
else {
StringBuilder stb = new StringBuilder();
stb.append(priceguid + " : " + xmlStreamReader.getLocalName() + " : " );
MapForAttributes.put(stb.toString(), "null");
}
}