Testing if XML contains a fragment

Help
tamsin
2011-10-26
2013-03-03
  • tamsin

    tamsin - 2011-10-26

    Hi,

    What would be the best way to check that my test XML contains a certain XML fragment?

    For example, my main XML file has several <test-item> nodes, and my XML fragment defines a single <test-item> node.

    I have managed by traversing the main document, creating a new Document for each <test-item> node, and comparing it to the XML fragment, so see if any of them match.

    This seems a bit long winded, and I wondered if there is a better way to do it?

    Thanks,
    Tamsin

     
  • Stefan Bodewig

    Stefan Bodewig - 2011-10-28

    Not much better, but at least a bit:

    Use the XPathEngine to get all test-item nodes rather than traversal.  And then use DifferenceEngine's compare method directly which accepts two Node instances, you don't need to create new Documents that way.

     
  • sonicaaaa

    sonicaaaa - 2013-02-14

    I had the same use case and I have solved like bodewig suggested, but I do believe that an addition to the API for this scenario would be a great addition to this useful library.

    t

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks