开发者社区> 问答> 正文

使用JAVA更正两个文件xml之间的传输位置标记

我用这部分来做我的工作,我的问题很简单。只是更改转帐地点。我不知道负责确定第一内容或最后内容中的运输地点的是什么问题。

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;
    Document doc = null;
    Document doc2 = null;
String a = "E:\\1.xml" ;
String  c ;
    try {
            db = dbf.newDocumentBuilder();
            doc = db.parse(new File(a));
            doc2 = db.parse(new File("E:\\L (1).xml"));
            NodeList ndListFirstFile = doc.getElementsByTagName("med");
            Node nodeArea = doc.importNode(doc2.getElementsByTagName("end").item(0), true);
        NodeList nList2 = doc2.getElementsByTagName("end");
            for (int i = f; i <g; i++) {
                c = +i+"" ;
               doc2 = db.parse(new File("E:\\L ("+c+").xml"));
            for (int temp = 0; temp < nList2.getLength(); temp++) {
                nodeArea = doc.importNode(doc2.getElementsByTagName("end").item(temp), true);
                   ndListFirstFile.item(0).appendChild(nodeArea);
            }  }

这是通过两个文件完成的,并且效果很好,但是传输标记的位置位于内容的末尾。我想在内容的开头

<med>
I move the Tag "dat" and it is moved at the end of the Tag "med" content
<dat>We have come to the wrong place, my friend</dat></med>

<med><dat>We want to get better here</dat>
I want to move Tag dat
To be the first content from Tag med
</med>

而已

展开
收起
垚tutu 2019-12-12 09:23:34 566 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载