Forum Discussion

ThomasAu's avatar
ThomasAu
Contributor
14 years ago

assert multiple nodes while ignoring namespace?

I found that I can assert a single nodeAND ignore namespace

<Response xmlns="http://uri.foo">
<node1>123</node1>
<node2>ABC</node2>


by using:
exists(//*[local-name()='node1']/*[local-name()='node2'])



what if I want to assert the whole chunk and also use wildcards?


for instance:


<Response xmlns="http://uri.foo">
<node1>123</node1>
<node2>ABC</node2>
<node2a>thisChanges</node2a>
<node3>foo</node3>
<node3a>thisChanges</node3a>
</node1>


So, I want to make sure that if node1 = 123, then node2 = ABC, node2a = *, node3 = foo, and node3a = *.

I was hoping I could declare the following:

//*[local-name()='Response']


and have expected result:

<node1>123</node1>
<node2>ABC</node2>
<node2a>*</node2a>
<node3>foo</node3>
<node3a>*</node3a>
</node1>



Any ideas?

3 Replies

  • here is another example of code:


    <Response xmlns="http://iWantToIgnoreThis">
    <H1>
    <H2>
    <e>
    <n1>BOB</n1>
    <n2>Boston</n2>
    <n3>384-389-3812</n3>
    <n4>xyz34</n4>
    </e>
    <e>
    <n1>JOHN</n1>
    <n2>Miami</n2>
    <n3>204-942-2034</n3>
    <n4>abadafeadsflasdf</n4>
    </e>
    <e>
    <n1>ADAM</n1>
    <n2>New York</n2>
    <n3>123-392-2934</n3>
    <n4>random</n4>
    </e>


    So, here, I want to assert to make sure that "ADAM" always has "New York".

    If I try:


    ((//*[local-name()='H1']/*[local-name()='H2']/*[local-name()='e']/*[local-name()='n1'])="ADAM") and ((//*[local-name()='H1']/*[local-name()='H2']/*[local-name()='e']/*[local-name()='n2'])="New York")


    for true, then it will pass.

    however, if I did the same thing but change "n2" to "Boston", it will still work. because there is a node n2 with "Boston".

    ideally, i want to somehow say, look inside //H1/H2/e, and make sure all of this is in it. and put that whole entire chunk between the <e> in. And have "n4" be a wildcard.
  • Firstly the XML you pasted was incomplete.. so have created the complete XML.


    <Response xmlns="http://iWantToIgnoreThis">
    <H1>
    <H2>
    <e>
    <n1>BOB</n1>
    <n2>Boston</n2>
    <n4>xyz34</n4>
    </e>
    <e>
    <n1>JOHN</n1>
    <n2>Miami</n2>
    <n4>abadafeadsflasdf</n4>
    </e>
    </H2>
    </H1>
    </Response>


    Now using this XML, you can verify that BOB is from Boston & JOHN is from Miami by placing 2 xpath assertions (ignoring namespaces).
    (((//*:H2/*:e[1]/*:n1)="BOB") and ((//*:H2/*:e[1]/*:n2)="Boston"))

    (((//*:H2/*:e[2]/*:n1)="JOHN") and ((//*:H2/*:e[2]/*:n2)="Miami"))

    I hope this would help.
    Regards,
    /Pradeep Bishnoi
    http://learnsoapui.wordpress.com
  • Thanks.

    But, I feel like there must be an easier way. Is there someway to declare

    //*:H2/*:e

    and have the expected result be:

    <n1>BOB</n1>
    <n2>Boston</n2>
    <n3>384-389-3812</n3>
    <n4>*</n4>



    I'm reading http://www.soapui.org/Functional-Testin ... tions.html and it seems like it's possible, but i can't seem to get the syntax right using the function to ignore namespaces...