我正在尝试使用 Windows 的任务调度程序 xml 文件。对于不知道的人,xml文件如下所示:
<?xml version="1.0" encoding="UTF-16"?>
<Tasks>
<!-- \job1 -->
<Task version="1.2"
xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2013-08-03T13:07:36.8791439</Date>
<Author>pc\laptop</Author>
</RegistrationInfo>
...
<!-- \job2 -->
<Task version="1.2"
......
我需要将“job1”值分配给一个数组。为此,我做了这个 java 代码:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setIgnoringComments(false);
NodeList jobList = el.getElementsByTagName("Tasks");
NodeList ndList = el.getElementsByTagName("Task");
for (int i = 0; i < ndList.getLength(); i++) {
Node childNode2 = jobList.item(i);
Node childNode = ndList.item(i);
if (childNode2.getNodeType() == Node.COMMENT_NODE) {
//Element jElement = (Element) childNode2;
//jElement.toString();
System.out.println(childNode2.getNodeType());
}
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) childNode;
System.out.println("Date : " + getTagValue("Date", eElement));
//some other codes....
}
但我无法到达那个评论区。第二件事是我怎样才能走进评论区。例如,我如何编写一个 for 循环?