Menu

partial matching on attributes and search order for matching nodes

Help
Constantin
2018-10-05
2018-12-09
  • Constantin

    Constantin - 2018-10-05

    Hello,

    1. Is there a way to use partial matching when establishing the order in which nodes are compared?

    More specifically, something like passing an array of strings to ElementNameAndAttributeQualifier's constructor, but it should determine the nodes comparison order not on a perfect match on all the attributes from the string array, but on a partial match of these.

    Consider this example:
    <element attr2="101" attr1="3">
    <ellement2 attr3="n">2</ellement2>
    </element>
    <element attr2="101" attr1="3">
    <ellement2 attr3="n">1</ellement2>
    </element>

    <element attr2="101" attr1="TEST1-3">
    <ellement2 attr3="n">2</ellement2>
    </element>
    <element attr2="101" attr1="3">
    <ellement2 attr3="n">1</ellement2>
    </element>

    I'd like here:
    - control node 1 to be compared with test node 1 (due to a partial match on attr2="101");
    - control node 2 to be compared with test node 2 (due to a perfect match on element attr1="3" attr2="101");

    I know that a solution here is to use "attr2" in the constructor of ElementNameAndAttributeQualifier, but I want the same behaviour to happen also for partial matches on attr1.

    1. Default behaviour is that DifferenceEngine will start to search for the matching test Element at the same sequence number the control node is at.
      2.1. Is there a way to change this behavior to make it search from the first position in the test nodes?
      2.2. Is there a way to change this behavior to make it search from the first position in the test nodes analyzing only the nodes which were not matched for comparison already?

    Many thanks,
    Constantin

     
  • Stefan Bodewig

    Stefan Bodewig - 2018-10-07

    I think 1. and 2.2 can more or less be achieved by specifying more than one ElementSelector to DefaultNodeMatcher's constructor. It will try to match all nodes using the first ElementSelector then apply the second one only to the nodes that haven't been matched already and so on.

    For question 1 this might work by using byNameAndAllAttributes first get all "perfect matches" first and byName or byNameAndAttribites("attr2") second (I'm not sure I've understood your concept of partial match well enough).

    As for 2.1 - there is no way to configure the behavior right now.

     
    • Valentin Fleaca

      Valentin Fleaca - 2018-11-27

      Hi @Stefan Bodewig,

      I have some questions for you if you are so kind to help me out.
      1. Have you considered sorting the xml's before the actual comparison? If so, how would have you done it?

      2.For the missing nodes it is possible to obtain a xPath value (via a parent somehow)?

      Thank you very much!
      Valentin

       
  • Stefan Bodewig

    Stefan Bodewig - 2018-12-09

    @Valentin Fleaca this might better become a separate thread ;-)

    Sorting by element name would have the same effect as using any of the ElementSelectors that are sensitive to the element name, so I never considered it. If I wanted to perform any manipulation on the list of children prior to finding matches then I'd probably implement this as part of a custom NodeMatcher.

    In the case of missing nodes you should look at the parent XPath property of the details for the node that is part of the Difference, see https://www.xmlunit.org/api/java/2.6.2/org/xmlunit/diff/Comparison.Detail.html#getParentXPath--

     

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.