1

私は持っている:

<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のみを使用して同じことをしたい

手伝ってくれてありがとう!

4

1 に答える 1