<?xml version="1.0" encoding="UTF-8"?>
<locations>
<location id="83">
<location_name>name</location_name>
<company_name>company a</company_name>
<machines>
<machine id="12">A</machine>
<machine id="312">B</machine>
</machines>
</location>
<location id="85">
<location_name>name</location_name>
<company_name>company c</company_name>
<machines>
<machine id="21">A</machine>
<machine id="45">B</machine>
</machines>
</location>
</locations>
XOMを使用して、すべての場所の名前を取得しようとしていますが、方法がわかりません。
Element root = doc.getRootElement();
int i = 1;
Element child = (Element) root.getChild(i);
while(child != null)
{
System.out.println(child.getFirstChildElement("location_name").getValue());
child = (Element) root.getChild(i++);
}
しかし、これは機能しません。名のみが表示され、2番目のループではエラーが表示されます。
そして2番目の質問:何が重要ですかgetChildCount()
?