Java中的节点比较和替换

时间:2012-04-06 14:33:30

标签: java xml spring dom xml-parsing

我想比较2个XML文件“parent.xml”,“child.xml”, 然后检查一个节点是否存在于“parent.xml”中并且“child.xml”中是否存在,然后将这些节点添加到“child.xml”,它应该维护节点层次结构。

“Parent.xml”的结构

<chart>
<chartconf alignTicks="true" animation="true" backgroundColor="#FFFFFF" 
       borderColor="#4572A7" borderRadius="5" borderWidth="0" className="" defaultSeriesType="">
</chartconf>
<legend>
    <align>center</align>
    <backgroundColor>null</backgroundColor>
    <borderColor>#909090</borderColor> 
    <borderRadius>25</borderRadius>
</legend>
<credits>
    <enabled>true</enabled>
    <position></position>
    <href>http://www.saama.com</href>
    <style bek="5555s">Sixth</style>
    <text>Highcharts.com</text>
</credits>
<license>
    <info>
        <url>http://eee.example.com</url>
        <author>Jhon Doe</author>
        <email>xyz@example.com</email>
        <type>GNU, MIT dual</type>
    </info>
</license>

“child.xml”的结构

<chart renderTo="pieContainer" >
<title align="center" text="Test Title" style="" verticalAlign=""></title>
<credits enabled="false" position="" href="" style="" text=""></credits>

<tooltip>
    <formatter>[function]function() {return this.point.name + " - " + this.percentage;}[/function]</formatter>
</tooltip>
<exporting enabled="true"></exporting>
<plotOptions>
    <pie allowPointSelect="true" cursor="pointer">
        <dataLabels align="left" enabled="true"></dataLabels>
        <series cursor="pointer" allowPointSelect="true">
            <events>
                <click>[function]function(event) {getAjaxData("ajax/pieDrill.json", this, event)}[/function]</click>
            </events>
        </series>
    </pie>
</plotOptions>

<license>
    <info>
        <url>http://eee.example.com</url>
        <author>Jhon Doe</url>
    </info>
</license></chart>

在“parent.xml”中,我们可以看到节点图例存在但不存在于子节点中,因此应将其添加到“child.xml”

第二个节点许可证存在于两个xml文件中,但在“child.xml”中缺少少数节点,因此我们可以添加那些缺少的节点,并且它应该保持相同的层次结构。

可以有n级嵌套,XML文件的格式不固定,可以随时更改

0 个答案:

没有答案
相关问题