Menu

Comparison between nodes with identical attributes

Help
2014-10-06
2014-10-08
  • Felipe Cepriano

    Felipe Cepriano - 2014-10-06

    Hi,

    I'd like to compare equal objects on two XML files with the same structure. For example, having the following inputs, it is comparing the object "TEXT" (the first attributeCfg inside object) with "IMAGE" (also the the first attributeCfg inside object, on the second XML).
    Is there any way to compare using a attribute (in this case, ATTRIBUTENAME=TEXT) to link two nodes so it would compare the first node of the first file to the second node on the second file?

    A)

    <objectStructure> <object name="BLOG" tableName="BLOG"> <attributeCfg> <column name="OBJECTNAME" value="BLOG"/> <column name="ATTRIBUTENAME" value="TEXT"/> <column name="ALIAS" value="TEXT"/> <column name="CLASSNAME" value=""/> <column name="DEFAULTVALUE" value=""/> <column name="LENGTH" value="8192"/> <column name="TYPE" value="LONGALN"/> <column name="TITLE" value="Blog Text"/> <column name="RESTRICTED" value="0"/> </attributeCfg> </object> </objectStructure>

    B)

    <objectStructure> <object name="BLOG" tableName="BLOG"> <attributeCfg> <column name="OBJECTNAME" value="BLOG"/> <column name="ATTRIBUTENAME" value="IMAGE"/> <column name="ALIAS" value="IMAGE"/> <column name="CLASSNAME" value=""/> <column name="DEFAULTVALUE" value=""/> <column name="LENGTH" value="254"/> <column name="TYPE" value="ALN"/> <column name="TITLE" value="Blog Image"/> <column name="RESTRICTED" value="0"/> </attributeCfg> <attributeCfg> <column name="OBJECTNAME" value="BLOG"/> <column name="ATTRIBUTENAME" value="TEXT"/> <column name="ALIAS" value="TEXT"/> <column name="CLASSNAME" value=""/> <column name="DEFAULTVALUE" value=""/> <column name="LENGTH" value="8192"/> <column name="TYPE" value="LONGALN"/> <column name="TITLE" value="Blog Text"/> <column name="RESTRICTED" value="0"/> </attributeCfg> </object> </objectStructure>

    Thanks in advance,

     
  • Stefan Bodewig

    Stefan Bodewig - 2014-10-08

    Yes, this is what ElementNameAndAttributeQualifier can be used for, you'd use the single-arg constructor and pass in "name".

    http://xmlunit.sourceforge.net/userguide/html/ar01s03.html#ElementQualifier

     

    Last edit: Stefan Bodewig 2014-10-08

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.