51,409
社区成员
发帖
与我相关
我的任务
分享<?xml version="1.0" encoding="UTF-8"?>
<resource>
<sysid>836</sysid>
<name>aaaaa1111111111111</name>
<type>3</type>
<summary>da11111111111111111</summary>
<file>
<fileid>3-000000</fileid>
<filerealname>course.csv</filerealname>
<filetype>0</filetype>
</file>
<file>
<fileid>2-000000</fileid>
<filetype>0</filetype>
</file>
<file>
<fileid>1-000000</fileid>
<filetype>0</filetype>
</file>
<podcastfile>\xx\res_836/podcast_836.xml</podcastfile>
<podcastcategory>xx</podcastcategory>
</resource><?xml version="1.0" encoding="UTF-8"?>
<resource>
<sysid>836</sysid>
<name>aaaaa1111111111111</name>
<type>3</type>
<summary>da11111111111111111</summary>
<file>
<fileid>2-000000</fileid>
<filetype>0</filetype>
</file>
<file>
<fileid>3-000000</fileid>
<filerealname>course.csv</filerealname>
<filetype>0</filetype>
</file>
<file>
<fileid>1-000000</fileid>
<filetype>0</filetype>
</file>
<podcastfile>\xx\res_836/podcast_836.xml</podcastfile>
<podcastcategory>xx</podcastcategory>
</resource>
String ids = "1,0,2,";
String[] index = ids.split(",");
List<String> idlist = new ArrayList<String>();
for(int i=0;i<index.length;i++){
String id = index[i].trim();
if(!",".equals(id)){
idlist.add(index[i].trim());
}
}
Document resoucedoc = XMLUtil.getXMLFileDocument(resoucefile);
NodeList resourcelist = resoucedoc.getElementsByTagName("resource");
NodeList filelist = resoucedoc.getElementsByTagName("file");
NodeList newFileList = resoucedoc.getElementsByTagName("file");
Element resource0 = (Element) resourcelist.item(0);
Node podcastfileNode = resource0.getElementsByTagName("podcastfile").item(0);
if(filelist!=null && filelist.getLength()>0){
for(int j=0;j<idlist.size();j++){
Node fileNode = null;
fileNode = newFileList.item(Integer.parseInt(idlist.get(j)));
// podcastfileNode.getParentNode().insertBefore(fileNode, podcastfileNode);
podcastfileNode.getParentNode().appendChild(fileNode);
}
}
XMLUtil.modifyFile(resoucedoc, resoucefile);
int len = filelist.getLength();
List<Node> newNodeList = new ArrayList<Node>();
for(int k=0;k<len;k++){
newNodeList.add(filelist.item(k));
}
然后把以前的“fileNode = newFileList.item(Integer.parseInt(idlist.get(j)));”中的newFileList改成newNodeList 就好了,不用它自身的这种集合,用我们处理后的集合