对于根有 25 个孩子的 xml 文件,getChildren 方法返回 list.size= 0 !!
这是我的代码:
public static void main(String[] args) {
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File("g:\\*");
try {
Document document = (Document) builder.build(xmlFile);
Element rootNode = document.getRootElement();
List list = rootNode.getChildren("job",Namespace.getNamespace("Montage"));
for (int i = 0; i < list.size(); i++)
{
Element node = (Element) list.get(i);
System.out.println("ID : " + node.getAttributeValue("id"));
System.out.println("Run Time : " + node.getAttributeValue("runtime"));
}
}
catch (IOException io) {
System.out.println(io.getMessage());
} catch (JDOMException jdomex) {
System.out.println(jdomex.getMessage());
}
}
这里是xml文件的部分:
<adag xmlns="http://pegasus.isi.edu/schema/DAX" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pegasus.isi.edu/schema/DAX http://pegasus.isi.edu/schema/dax-2.1.xsd" version="2.1" count="1" index="0" name="test" jobCount="25" fileCount="0" childCount="20">
<job id="ID00000" namespace="Montage" name="mProjectPP" version="1.0" runtime="13.39">
<uses file="region.hdr" link="input" register="true" transfer="true" optional="false" type="data" size="304" />
<uses file="2mass-atlas-ID00000s-jID00000.fits" link="input" register="true" transfer="true" optional="false" type="data" size="4222080" />
<uses file="p2mass-atlas-ID00000s-jID00000.fits" link="output" register="true" transfer="true" optional="false" type="data" size="4167312" />
<uses file="p2mass-atlas-ID00000s-jID00000_area.fits" link="output" register="true" transfer="true" optional="false" type="data" size="4167312" />
</job>
怎么了?