Hi Stefan,

Thank you for your reply. Appreciate it tons.
FYI - I  had posted the same query to the mailing list as well. Now marking
this email to it too.

Due to the lack of XMLUnit awareness around me, i turn to you for a detailed
discussion.


*Each Difference will carry the XPath of the nodes compared as well as
the DOM Node instances themselves.  This XPath will be index based and not
based on attributes so you will need to translate from there to your
ids.*

I understand that the differences generate the XPath of the nodes being
compared, what i was looking at was understanding as to how these difference
are generated.

I would like to records of my XMLs being compared instead of Line by Line
comaprison (records with unique identifiers).
We used the ElementNameQualifier Interface, did override it but it did not
bring about record comparison.

<Code> ElementQualifier overriden.
  public boolean qualifyForComparison(Element arg0, Element arg1)
    {

       try
       {

          if (arg0.getNodeName() != null
                && arg0.getNodeName().equals("POI")) /*Record Identifier is
the firstChild Node of teh Elelment POI and hence item(0)*/
          {
             if(arg0.getChildNodes().item(0).getTextContent()

.equals(arg1.getChildNodes().item(0).getTextContent()))
                return true;
             else
                return false;
          }
       }
       catch (Throwable t)//TODO add asserts
       {
          return false;
       }
       return true;
    }

<code>


<code>
   public static void diffXML(Document dom1, Document dom2) throws
SAXException, IOException
   {

      XMLUnit.setCompareUnmatched(false);
      XMLUnit.setIgnoreWhitespace(true);

      Diff diff = new Diff(dom1, dom2);

      DetailedDiff myDiff = new DetailedDiff(diff);
      // myDiff.overrideElementQualifier(new
RecursiveElementNameAndTextQualifier()); //DOESNT WORK!
      //myDiff.overrideElementQualifier(new
MultiLevelElementNameAndTextQualifier()); //DOESNT WORK!
      myDiff.overrideElementQualifier(new MyElementQualifier());
      List<Difference> allDifferences = (List<Difference>)
myDiff.getAllDifferences();

      /*Can be converted into a HashMap and then keep the POI-Entity-id as
the key
       * and the rest it differences so grouped differences.
       * */
      for (Difference currentDiff : allDifferences)
      {
         switch (currentDiff.getId())
         {

            case DifferenceConstants.CHILD_NODELIST_SEQUENCE_ID:

               break; //noop
            /*
             * Sneha -Start
             */
            /*case DifferenceConstants.ATTR_NAME_NOT_FOUND_ID:
                Same as Child Not Found
                Only logging different
                break;

            case DifferenceConstants.ATTR_VALUE_ID:
                Same as Child Not Found
                Only logging different
                break;*/

            /*Sneha - End
             * */
            case DifferenceConstants.CHILD_NODE_NOT_FOUND_ID:
               NodeDetail tempNodeDetail =
currentDiff.getControlNodeDetail();

               Document tempDom = dom1;
               if (tempNodeDetail.getNode() == null)
               {
                  tempNodeDetail = currentDiff.getTestNodeDetail();
                  System.out.println("Here");
                  tempDom = dom2;
               }
               if (tempNodeDetail.getNode() != null)
                  System.out.println(" Element " +
tempNodeDetail.getNode().getNodeName() + " absent in the other for record
"+getRecordNumberFromNode(tempNodeDetail.getXpathLocation(),tempDom));
               break;

            case DifferenceConstants.CHILD_NODELIST_LENGTH_ID:
                break;

            case DifferenceConstants.TEXT_VALUE_ID:
                System.out.println(" Value of element
"+currentDiff.getControlNodeDetail().getNode().getParentNode().getNodeName()+
" mismatch for record
"+getRecordNumberFromNode(currentDiff.getControlNodeDetail().getXpathLocation(),dom1));
                break;

            default:

               System.out.println(" TYPE = " + currentDiff.getId());
               System.out.println(" " +
currentDiff.getControlNodeDetail().getXpathLocation());
               System.out.println(" XML1: " +
currentDiff.getControlNodeDetail().getValue());
               System.out.println(" " +
currentDiff.getTestNodeDetail().getXpathLocation());
               System.out.println(" XML2: " +
currentDiff.getTestNodeDetail().getValue());
               System.out.println(currentDiff.getDescription());
               System.out.println();
         }

      }
   }

   private static String getRecordNumberFromNode(String xpathString,
Document dom)
   {
      //if (!xpathString.contains("item_tuple"))
      if (!xpathString.contains("POI"))
         return null;
      System.out.println(dom);
      xpathString =
xpathString.substring(0,xpathString.indexOf("POI")+"POI".length()+3) +
"/POI_Entity_ID";
      System.out.println(xpathString);

      try
      {
         XPathExpression xpathExp = xpath.compile(xpathString);
         String record = xpathExp.evaluate(dom);

         return record;
      }
      catch (XPathExpressionException e)
      {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      return "";


   }

<code>

Regards,
Sneha.





On Tue, Apr 13, 2010 at 8:54 PM, Stefan Bodewig <[email protected]> wrote:

> Hi Sneha,
>
> I'd appreciate if you could use the official support channels of XMLUnit
> (basically the mailing list but I could live with the web forum at
> sourceforge) even if I'd probably be the only one to answer.  That way
> the answer gets archived and can be reused by the next person with the
> same question.
>
> On 2010-04-06, Sneha Teckchandani <[email protected]> wrote:
>
> > The result expected is not only an assertion of whether the XMLs are
> similar
> > or different but also to present the various differences.
> > This to be done irrespective to the position of the various XML records.
>
> > Based on my understanding of XMLUnit, it provides only assertion type
> > results. Except for the method Diff.getAllDifferences() .
>
> Not quite.  For the full picture you really should read section 3 of the
> user manual and tell me where I need to add more flesh to make it
> better understandable. 8-)
>
> In your case you don't want to use any of the assertion methods but the
> DetailedDiff class (in order to find all differences), see Example 22 in
> the user manual.
>
> > If you can help in understanding/implementing XMLUnit not just as a
> testing
> > tool but also for comparing XML files based on a unique
> Record-Identifier,
> > would appreciate it ton.
>
> Each Difference will carry the XPath of the nodes compared as well as
> the DOM Node instances themselves.  This XPath will be index based and not
> based on attributes so you will need to translate from there to your
> ids.
>


>
> Cheers
>
>        Stefan
>



-- 
Thanks & Regards,
Sneha Teckchandani.

do your best positively, accept the results gracefully!
<?xml version="1.0" encoding="UTF-8"?>
<DeliveryPackage xmlns:saxon="http://saxon.sf.net/";
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                 xmlns:ext="java:com.navtech.cci.common.Utilities"
                 VersionNo="Q110"
                 CreationTime="2010-02-25T01:27:51.222-06:00"
                 MapVersion="NA 10 01 01"
                 Language_Code_Desc="../DEFINITIONS/language.xml"
                 Country_Code_Desc="../DEFINITIONS/country.xml"
                 Supplier_Code_Desc="../DEFINITIONS/supplier.xml"
                 XY_Type="WGS84"
                 Category_Code_Desc="../DEFINITIONS/category.xml"
                 Chain_Brand_Desc="../DEFINITIONS/chain_brand.xml"
                 Char_Set="UTF-8"
                 UpdateType="BulkUpdate"
                 Coverage="D02"
                 Category="5540">
   <POI>
	  <POI_Entity_ID>12009</POI_Entity_ID>
      <Action>Add</Action>
      <SupplierID>3</SupplierID>
      <Identity>
         <Names>
            <POI_Name Language_Code="ENG">
               <Text>Portside Conoco</Text>
            </POI_Name>
         </Names>
         <Category_ID Type="NT">5540</Category_ID>
         <Product_Type>12</Product_Type>
      </Identity>
      <Locations>
         <Location>
            <Address>
               <ParsedAddress>
                  <ParsedStreetAddress>
                     <Address_Number>
                        <House_Number>1829</House_Number>
                     </Address_Number>
                     <ParsedStreetName>
                        <StreetName Language_Code="ENG">1ST</StreetName>
                        <StreetType Attached="false" Before="false" Language_Code="ENG">ST</StreetType>
                        <Prefix>S</Prefix>
                     </ParsedStreetName>
                  </ParsedStreetAddress>
                  <ParsedPlace>
                     <PlaceLevel2 Language_Code="ENG">WASHINGTON</PlaceLevel2>
                     <PlaceLevel3 Language_Code="ENG">YAKIMA</PlaceLevel3>
                     <PlaceLevel4 Language_Code="ENG">SUNNYSIDE</PlaceLevel4>
                  </ParsedPlace>
                  <PostalCode>
                     <NT_Postal>98944</NT_Postal>
                  </PostalCode>
                  <CountryCode>USA</CountryCode>
               </ParsedAddress>
            </Address>
            <GeoPosition>
               <Latitude>46.30857</Latitude>
               <Longitude>-120.02023</Longitude>
            </GeoPosition>
            <MapLinkID>
               <LinkID>124514627</LinkID>
               <Side_of_Street>L</Side_of_Street>
               <Percent_from_RefNode>60</Percent_from_RefNode>
            </MapLinkID>
            <Confidence>
               <Match_Level>GeoPoint</Match_Level>
            </Confidence>
         </Location>
      </Locations>
      <Contacts>
         <Contact Type="Main" Language_Code="ENG">
            <Number Type="Phone Number" Preferred="YES">509-8379066</Number>
         </Contact>
      </Contacts>
      <Products_Services>
         <Fuels>
            <E85>true</E85>
         </Fuels>
         <Open_24_Hours>true</Open_24_Hours>
      </Products_Services>
      <Details>
         <Private_Access>false</Private_Access>
      </Details>
   </POI>
</DeliveryPackage>
<?xml version="1.0" encoding="UTF-8"?>
<DeliveryPackage xmlns:saxon="http://saxon.sf.net/";
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                 xmlns:ext="java:com.navtech.cci.common.Utilities"
                 VersionNo="Q110"
                 CreationTime="2010-02-25T01:27:51.222-06:00"
                 MapVersion="NA 10 01 01"
                 Language_Code_Desc="../DEFINITIONS/language.xml"
                 Country_Code_Desc="../DEFINITIONS/country.xml"
                 Supplier_Code_Desc="../DEFINITIONS/supplier.xml"
                 XY_Type="WGS84"
                 Category_Code_Desc="../DEFINITIONS/category.xml"
                 Chain_Brand_Desc="../DEFINITIONS/chain_brand.xml"
                 Char_Set="UTF-8"
                 UpdateType="BulkUpdate"
                 Coverage="D02"
                 Category="5540">
   <POI>
	  <POI_Entity_ID>12009</POI_Entity_ID>
      <Action>Add</Action>
      <SupplierID>3</SupplierID>
      <Identity>
         <Names>
            <POI_Name Language_Code="ENG">
               <Text>Portside Conoco</Text>
            </POI_Name>
         </Names>
         <Category_ID Type="NT">5540</Category_ID>
         <Product_Type>12</Product_Type>
      </Identity>
      <Locations>
         <Location>
            <Address>
               <ParsedAddress>
                  <ParsedStreetAddress>
                     <Address_Number>
                        <House_Number>1829</House_Number>
                     </Address_Number>
                     <ParsedStreetName>
                        <StreetName Language_Code="ENG">1ST</StreetName>
                        <StreetType Attached="false" Before="false" Language_Code="ENG">ST</StreetType>
                        <Prefix>S</Prefix>
                     </ParsedStreetName>
                  </ParsedStreetAddress>
                  <ParsedPlace>
                     <PlaceLevel2 Language_Code="ENG">WASHINGTON</PlaceLevel2>
                     <PlaceLevel3 Language_Code="ENG">YAKIMA</PlaceLevel3>
                     <PlaceLevel4 Language_Code="ENG">SUNNYSIDE</PlaceLevel4>
                  </ParsedPlace>
                  <PostalCode>
                     <NT_Postal>98944</NT_Postal>
                  </PostalCode>
                  <CountryCode>USA</CountryCode>
               </ParsedAddress>
            </Address>
            <GeoPosition>
               <Latitude>46.30857</Latitude>
               <Longitude>-120.02023</Longitude>
            </GeoPosition>
            <MapLinkID>
               <LinkID>124514627</LinkID>
               <Side_of_Street>L</Side_of_Street>
               <Percent_from_RefNode>60</Percent_from_RefNode>
            </MapLinkID>
            <Confidence>
               <Match_Level>GeoPoint</Match_Level>
            </Confidence>
         </Location>
      </Locations>
      <Contacts>
         <Contact Type="Main" Language_Code="ENG">
            <Number Type="Phone Number" Preferred="YES">509-8379066</Number>
         </Contact>
      </Contacts>
      <Products_Services>
         <Fuels>
            <E85>true</E85>
         </Fuels>
         <Open_24_Hours>true</Open_24_Hours>
      </Products_Services>
      <Details>
         <Private_Access>false</Private_Access>
      </Details>
   </POI>
   <POI>
	  <POI_Entity_ID>12610</POI_Entity_ID>
      <Action>Add</Action>
      <SupplierID>3</SupplierID>
      <Identity>
         <Names>
            <POI_Name Language_Code="ENG">
               <Text>Flame Propane</Text>
            </POI_Name>
         </Names>
         <Category_ID Type="NT">5540</Category_ID>
         <Product_Type>12</Product_Type>
      </Identity>
      <Locations>
         <Location>
            <Address>
               <ParsedAddress>
                  <ParsedStreetAddress>
                     <Address_Number>
                        <House_Number>475</House_Number>
                     </Address_Number>
                     <ParsedStreetName>
                        <StreetName Language_Code="ENG">6TH</StreetName>
                        <StreetType Attached="false" Before="false" Language_Code="ENG">ST</StreetType>
                     </ParsedStreetName>
                  </ParsedStreetAddress>
                  <ParsedPlace>
                     <PlaceLevel2 Language_Code="ENG">ARIZONA</PlaceLevel2>
                     <PlaceLevel3 Language_Code="ENG">YAVAPAI</PlaceLevel3>
                     <PlaceLevel4 Language_Code="ENG">PRESCOTT</PlaceLevel4>
                  </ParsedPlace>
                  <PostalCode>
                     <NT_Postal>86301</NT_Postal>
                  </PostalCode>
                  <CountryCode>USA</CountryCode>
               </ParsedAddress>
            </Address>
            <GeoPosition>
               <Latitude>34.54804</Latitude>
               <Longitude>-112.46545</Longitude>
            </GeoPosition>
            <MapLinkID>
               <LinkID>97594255</LinkID>
               <Side_of_Street>R</Side_of_Street>
               <Percent_from_RefNode>70</Percent_from_RefNode>
            </MapLinkID>
            <Confidence>
               <Match_Level>GeoPoint</Match_Level>
            </Confidence>
         </Location>
      </Locations>
      <Contacts>
         <Contact Type="Main" Language_Code="ENG">
            <Number Type="Phone Number" Preferred="YES">928-4453191</Number>
         </Contact>
      </Contacts>
      <Products_Services>
         <Fuels>
            <LPG>true</LPG>
         </Fuels>
         <Open_24_Hours>false</Open_24_Hours>
      </Products_Services>
      <Details>
         <Private_Access>false</Private_Access>
      </Details>
   </POI>
    <POI>
      <POI_Entity_ID>1728</POI_Entity_ID>
      <Action>Add</Action>
      <SupplierID>3</SupplierID>
      <Identity>
         <Names>
            <POI_Name Language_Code="ENG">
               <Text>Clean Energy - Diamond Shamrock</Text>
            </POI_Name>
         </Names>
         <Category_ID Type="NT">5540</Category_ID>
         <Product_Type>12</Product_Type>
      </Identity>
      <Locations>
         <Location>
            <Address>
               <ParsedAddress>
                  <ParsedStreetAddress>
                     <Address_Number>
                        <House_Number>722</House_Number>
                     </Address_Number>
                     <ParsedStreetName>
                        <StreetName Language_Code="ENG">KIPLING</StreetName>
                        <StreetType Attached="false" Before="false" Language_Code="ENG">ST</StreetType>
                     </ParsedStreetName>
                  </ParsedStreetAddress>
                  <ParsedPlace>
                     <PlaceLevel2 Language_Code="ENG">COLORADO</PlaceLevel2>
                     <PlaceLevel3 Language_Code="ENG">JEFFERSON</PlaceLevel3>
                     <PlaceLevel4 Language_Code="ENG">LAKEWOOD</PlaceLevel4>
                  </ParsedPlace>
                  <Zone Language_Code="ENG" Type="PA">DENVER</Zone>
                  <PostalCode>
                     <NT_Postal>80215</NT_Postal>
                  </PostalCode>
                  <CountryCode>USA</CountryCode>
               </ParsedAddress>
            </Address>
            <GeoPosition>
               <Latitude>39.7284</Latitude>
               <Longitude>-105.10964</Longitude>
            </GeoPosition>
            <MapLinkID>
               <LinkID>704527750</LinkID>
               <Side_of_Street>R</Side_of_Street>
               <Percent_from_RefNode>50</Percent_from_RefNode>
            </MapLinkID>
            <Confidence>
               <Match_Level>GeoPoint</Match_Level>
            </Confidence>
         </Location>
      </Locations>
      <Contacts>
         <Contact Type="Main" Language_Code="ENG">
            <Number Type="Phone Number" Preferred="YES">800-3664602</Number>
         </Contact>
      </Contacts>
      <Products_Services>
         <Fuels>
            <CNG>true</CNG>
         </Fuels>
         <Open_24_Hours>false</Open_24_Hours>
      </Products_Services>
      <Details>
         <Private_Access>false</Private_Access>
      </Details>
   </POI>
</DeliveryPackage>
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Xmlunit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/xmlunit-general

Reply via email to