Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

XMLUnit

Options
  • 13-06-2008 11:55am
    #1
    Moderators, Science, Health & Environment Moderators Posts: 10,079 Mod ✭✭✭✭


    Hi I have a problem with XPath and XMLUnit.

    I have two versions of an xml file one with namespace declarations and one without. Basically what I am trying to do is check if an element exists in the xml file using Xpath expression and XMLUnit test methods.

    When I use the second version of the file the test passes ok. But when I use the first version of the file the test fails.

    I am calling the test method as follows: The parameters are an Xpath expression and a document. If the element exists the method does nothing, if it fails and Assertion Error is thrown.

    //Fails
    XMLAssert.assertXpathExists("/Book/Title", xml1);

    //Suceeds
    XMLAssert.assertXpathExists("/Book/Title", xml2);


    XML File 1
    <?xml version="1.0" encoding="UTF-8"?>
    <Book xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"   
    xmlns="http://www.publishing.org"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.publishing.org tests/etc/Book.xsd"> 
         <Title id="123">The Book</Title> 
         <ISBN>1-55874-262-X</ISBN>
         <Publisher>Acme Communications, Inc.</Publisher>
    </Book>
    

    XML File 2
    <?xml version="1.0" encoding="UTF-8"?>
    <Book> 
        <Title id="123">The Book</Title> 
        <ISBN>1-55874-262-X</ISBN>
        <Publisher>Acme Communications, Inc.</Publisher>
    </Book>"
    

    Any ideas? Changing the xml is not an option unfortunately.
    Thanks lads.


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 10,079 Mod ✭✭✭✭marco_polo


    Seems to not like the default namespace. I found this dirty hack it seems to do the trick. Not very pretty it must be said. If anyone has any better suggestions then let me know

    //*[local-name()="Book"]/*[local-name()="Title"]


Advertisement