我在一个包含多个属性的文件中有一个XML字段。我该如何打印出来。我的以下代码只打印一个.. XML文件: 0.52
代码:
public void startElement(String nameSpaceURI,
String localName,
String qName,
Attributes atts) {
int attributeLength = atts.getLength();
for (int i = 0; i < attributeLength; i++) {
String attrName = atts.getLocalName(i);
String attrVal = atts.getValue(i);
}
System.out.print("<" + qName + attrName + attrVal + ">");
}
提前感谢您的帮助!!
答案 0 :(得分:0)
它将被编译,因为它将具有至少一个属性值。但是,我找到了我正在寻找的简单解决方案..
public void startElement(String nameSpaceURI, 字符串localName, 字符串qName, 属性atts){
StringBuilder attribute = new StringBuilder("");
int attributeLength = atts.getLength();
for (int i = 0; i < attributeLength; i++) {
String attrName = atts.getLocalName(i);
String attrVal = atts.getValue(i);
attribute.append(" " + attrName + "=" + "\"" + attrVal + "\"");
}
System.out.print("<" + qName + attribute + ">");
}