java - How can I compare 2 xml files for changed nodes? -
i have 2 xml files a.xml , b.xml, b.xml modified version of a.xml node values have been changed. want make check in code particular node values can changed not nodes. how can make check in java? getting xml user , allowed change particular nodes if changes other nodes should not allow .below xml can see
<xt:path>helloworld/businessservices/mytest</xt:path> has changed in both valid case has changed
<xt:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/xmlschema">40</xt:value> 30 40 not valid.
a.xml
<?xml version="1.0" encoding="utf-8"?> <cus:customizations xmlns:cus="http://www.bea.com/wli/config/customizations" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xt="http://www.bea.com/wli/config/xmltypes"> <cus:customization xsi:type="cus:envvaluecustomizationtype"> <cus:description/> <cus:envvalueassignments> <xt:envvaluetype>service uri weight</xt:envvaluetype> <xt:location>0</xt:location> <xt:owner> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </xt:owner> <xt:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/xmlschema">0</xt:value> </cus:envvalueassignments> <cus:envvalueassignments> <xt:envvaluetype>service uri</xt:envvaluetype> <xt:location>0</xt:location> <xt:owner> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </xt:owner> <xt:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/xmlschema">jejb:oracle:test</xt:value> </cus:envvalueassignments> <cus:envvalueassignments> <xt:envvaluetype>service uri table</xt:envvaluetype> <xt:location xsi:nil="true"/> <xt:owner> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </xt:owner> <xt:value> <tableelement xmlns="http://www.bea.com/wli/sb/transports"> <uri>jejb:oracle:test</uri> <weight>0</weight> </tableelement> </xt:value> </cus:envvalueassignments> <cus:envvalueassignments> <xt:envvaluetype>service retry count</xt:envvaluetype> <xt:location xsi:nil="true"/> <xt:owner> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </xt:owner> <xt:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/xmlschema">0</xt:value> </cus:envvalueassignments> <cus:envvalueassignments> <xt:envvaluetype>service retry iteration interval</xt:envvaluetype> <xt:location xsi:nil="true"/> <xt:owner> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </xt:owner> <xt:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/xmlschema">30</xt:value> </cus:envvalueassignments> </cus:customization> <cus:customization xsi:type="cus:findandreplacecustomizationtype"> <cus:description/> <cus:query> <xt:resourcetypes>businessservice</xt:resourcetypes> <xt:envvaluetypes>service retry iteration interval</xt:envvaluetypes> <xt:envvaluetypes>service uri weight</xt:envvaluetypes> <xt:envvaluetypes>service retry count</xt:envvaluetypes> <xt:envvaluetypes>service uri</xt:envvaluetypes> <xt:refstosearch xsi:type="xt:resourcereftype"> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </xt:refstosearch> <xt:includeonlymodifiedresources>false</xt:includeonlymodifiedresources> <xt:searchstring>search string</xt:searchstring> <xt:iscompletematch>false</xt:iscompletematch> </cus:query> <cus:replacement>replacement string</cus:replacement> </cus:customization> <cus:customization xsi:type="cus:referencecustomizationtype"> <cus:description/> <cus:refstobeconsidered xsi:type="xt:resourcereftype"> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </cus:refstobeconsidered> <cus:externalreferencemap> <xt:oldref> <xt:type>foreignjndiprovider</xt:type> <xt:path>system/jndi providers/oracle</xt:path> </xt:oldref> <xt:newref> <xt:type>foreignjndiprovider</xt:type> <xt:path>system/jndi providers/oracle</xt:path> </xt:newref> </cus:externalreferencemap> <cus:externalreferencemap> <xt:oldref> <xt:type>archive</xt:type> <xt:path>dev/helloosbejbclient</xt:path> </xt:oldref> <xt:newref> <xt:type>archive</xt:type> <xt:path>dev/helloosbejbclient</xt:path> </xt:newref> </cus:externalreferencemap> </cus:customization> </cus:customizations> b.xml
<?xml version="1.0" encoding="utf-8"?> <cus:customizations xmlns:cus="http://www.bea.com/wli/config/customizations" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xt="http://www.bea.com/wli/config/xmltypes"> <cus:customization xsi:type="cus:envvaluecustomizationtype"> <cus:description/> <cus:envvalueassignments> <xt:envvaluetype>service uri weight</xt:envvaluetype> <xt:location>0</xt:location> <xt:owner> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </xt:owner> <xt:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/xmlschema">0</xt:value> </cus:envvalueassignments> <cus:envvalueassignments> <xt:envvaluetype>service uri</xt:envvaluetype> <xt:location>0</xt:location> <xt:owner> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </xt:owner> <xt:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/xmlschema">jejb:oracle:test</xt:value> </cus:envvalueassignments> <cus:envvalueassignments> <xt:envvaluetype>service uri table</xt:envvaluetype> <xt:location xsi:nil="true"/> <xt:owner> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </xt:owner> <xt:value> <tableelement xmlns="http://www.bea.com/wli/sb/transports"> <uri>jejb:oracle:test</uri> <weight>0</weight> </tableelement> </xt:value> </cus:envvalueassignments> <cus:envvalueassignments> <xt:envvaluetype>service retry count</xt:envvaluetype> <xt:location xsi:nil="true"/> <xt:owner> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </xt:owner> <xt:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/xmlschema">0</xt:value> </cus:envvalueassignments> <cus:envvalueassignments> <xt:envvaluetype>service retry iteration interval</xt:envvaluetype> <xt:location xsi:nil="true"/> <xt:owner> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/mytest</xt:path> </xt:owner> <xt:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/xmlschema">40</xt:value> </cus:envvalueassignments> </cus:customization> <cus:customization xsi:type="cus:findandreplacecustomizationtype"> <cus:description/> <cus:query> <xt:resourcetypes>businessservice</xt:resourcetypes> <xt:envvaluetypes>service retry iteration interval</xt:envvaluetypes> <xt:envvaluetypes>service uri weight</xt:envvaluetypes> <xt:envvaluetypes>service retry count</xt:envvaluetypes> <xt:envvaluetypes>service uri</xt:envvaluetypes> <xt:refstosearch xsi:type="xt:resourcereftype"> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/mytest</xt:path> </xt:refstosearch> <xt:includeonlymodifiedresources>false</xt:includeonlymodifiedresources> <xt:searchstring>search string</xt:searchstring> <xt:iscompletematch>false</xt:iscompletematch> </cus:query> <cus:replacement>replacement string</cus:replacement> </cus:customization> <cus:customization xsi:type="cus:referencecustomizationtype"> <cus:description/> <cus:refstobeconsidered xsi:type="xt:resourcereftype"> <xt:type>businessservice</xt:type> <xt:path>helloworld/businessservices/test123</xt:path> </cus:refstobeconsidered> <cus:externalreferencemap> <xt:oldref> <xt:type>foreignjndiprovider</xt:type> <xt:path>system/jndi providers/oracle</xt:path> </xt:oldref> <xt:newref> <xt:type>foreignjndiprovider</xt:type> <xt:path>system/jndi providers/oracle</xt:path> </xt:newref> </cus:externalreferencemap> <cus:externalreferencemap> <xt:oldref> <xt:type>archive</xt:type> <xt:path>dev/helloosbejbclient</xt:path> </xt:oldref> <xt:newref> <xt:type>archive</xt:type> <xt:path>dev/helloosbejbclient</xt:path> </xt:newref> </cus:externalreferencemap> </cus:customization> </cus:customizations>
hmm may read both files, documentbuilder. store nodes in example list can compare after reading them:
documentbuilderfactory fac = documentbuilderfactory.newinstance(); documentbuilder builder = fac.newdocumentbuilder(); document doc = builder.parse(new file("a.xml"); after can nodes out of document (stored in nodelist)
nodelist list = doc.getelementsbyname("someelement"); //just example hope little
Comments
Post a Comment