我有:
<root>
<element1 attribute11="first1" attribute12="second1">value1</element1>
<element2 attribute21="first2" attribute22="second2">value2</element2>
<element3>
<element31 attribute311="first31" attribute312="second31">value31</element31>
<element32 attribute321="first32" attribute322="second32">value32</element32>
</element3>
</root>
我想打印:
element1=value1
attribute11=first1
attribute12=second1
element2=value2
attribute21=first2
attribute22=second2
element31=value31
attribute311=first31
attribute312=second32
element31=value31
attribute321=first32
attribute322=second31
我可以使用 DOM 来实现这一点:
for (Element element : $(myXml).find("*")) {
if (!element.hasChildNodes()){
System.out.println("Element: "+element.getNodeName()+"="+$(element).text());
}
NamedNodeMap attributesList = element.getAttributes();
for (int j = 0; j < attributesList.getLength(); j++) {
System.out.println("Attribute: "
+ attributesList.item(j).getNodeName() + "="
+ attributesList.item(j).getNodeValue());
}
}
但我想在不使用 DOM 并且只使用joox的情况下做同样的事情
感谢帮助!