Hello,
I am trying to validate a response from a webservice that contains 3 tables with the same name:

...
<SUBTABLE3>
content
</SUBTABLE3>
...

<SUBTABLE3>
content
</SUBTABLE3>
...

<SUBTABLE3>
content
</SUBTABLE3>

...

I am using the example on:

The problem, the way I see it is when I use

declare namespace sam='';
//some tag/some tag/SUBTABLE3

I get erro because it cannot distinguish between the nodes when there are several nodes with the same name (SUBTABLE3).

Is there way to solve this problem?

Cheers

Magnus

Dani AI

Generated

Short primer and the immediate fix for : pick the SUBTABLE3 row by testing a child value, not by numeric position. Positional predicates (first/second) work, but they break if the server reorders rows. Instead use a predicate that matches the SUBTABLE3 whose child element (the identifier column) equals the expected ID — that returns the specific row you want. (w3.org)

Namespaces in the SOAP wrapper are the usual nuisance. Two practical options in SoapUI: declare a prefix for the response namespace and write a prefix-qualified XPath, or write a namespace-agnostic XPath using local-name() so you do not need to manage prefixes. Example (namespace-agnostic) that selects the tid_tekst for the SUBTABLE3 whose RF_nr child equals a value:

/*[local-name() = 'TABLE']/*[local-name() = 'SUBTABLE3' and ./*[local-name() = 'RF_nr'] = '0018']/*[local-name() = 'tid_tekst']/text()

Or declare a prefix and use it (replace the URI with the response namespace):

declare namespace p='http://tempuri.org/pensjonsdata';
/p:pensjonsdatatilEAWResponse//p:SUBTABLE3[p:RF_nr='0018']/p:tid_tekst

Using local-name() is a common pattern when namespaces vary. (stackoverflow.com)

SoapUI specifics and quick troubleshooting: use an XPath Match assertion (put the XPath in the expression and set the Expected Value to the date you expect), and wrap the selected node with normalize-space() if formatting/whitespace might differ. If the assertion fails, test the XPath in an external tester or use SoapUI’s Select XPath wizard to see what node is actually returned; check that the RF_nr value you filter on exactly matches the response text. These steps make the validation robust even when the response uses different prefixes or contains extra whitespace. (stackoverflow.com)

Recommended Answers

All 3 Replies

It's hard to see exactly what you want because I don't quite understand the problem. If you need to have different rules happen for each SUBTABLE3 element, you need some kind of predicate to differentiate them.

If they are all at the same level, you can use a positional predicate. Something like this would get you the FIRST one. You can change the predicate for the others.

/root/something/SUBTABLE3[1]

If there's some kind of content within the element that you're looking for, you can build a predicate that looks to make sure it contains what you're looking for as well. Hard to explain when I don't know what you're trying to do. You say validation, so is this related to schema? Or are you using XLST to check some data inside them?

Please make your question clear. Post a relevant snippet of input xml, your xslt code and the output required.

Hello,
I will try to be more spesific. I have an wsdl schema/request looking like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pen="http://tempuri.org/pensjonsdata">
   <soapenv:Header/>
   <soapenv:Body>
      <pen:pensjonsdatatilEAW>
         <pen:parameters>
            <pen:forsikringstNr>00403001</pen:forsikringstNr>
         </pen:parameters>
         <pen:streams>
            <pen:instream>
               <pen:Value>cid:845169188226</pen:Value>
            </pen:instream>
         </pen:streams>
      </pen:pensjonsdatatilEAW>
   </soapenv:Body>
</soapenv:Envelope>

And I have a response looking like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <m:pensjonsdatatilEAWResponse xmlns:m="http://tempuri.org/pensjonsdata">
         <m:pensjonsdatatilEAWResult>
            <axis2ns22:Streams xmlns:axis2ns22="http://tempuri.org/pensjonsdata">
               <axis2ns23:_WEBOUT contentType="text/xml;charset=windows-1252" xmlns:axis2ns23="http://tempuri.org/pensjonsdata">
                  <axis2ns24:Value xmlns:axis2ns24="http://tempuri.org/pensjonsdata">
                     <TABLE>
                        <SUBTABLE3>
                           <tid_tekst>01.01.2011</tid_tekst>
                           <kunde>Hamar Kommune</kunde>
                           <RF_nr>0013</RF_nr>
                           <RF>Sykepleiere</RF>
                           <gjennomsnittsalder>44.1791186</gjennomsnittsalder>
                           <gj_pensjonsgrunnlag_pr_aktiv>372656.828</gj_pensjonsgrunnlag_pr_aktiv>
                           <pensjonsgrunnlag>77512620.2</pensjonsgrunnlag>
                           <gj_pensjonsgrunnlag_pr_aarsverk>431795.522</gj_pensjonsgrunnlag_pr_aarsverk>
                           <gj_aktuell_deltid>0.86304005</gj_aktuell_deltid>
                           <uforeandel>0.1875</uforeandel>
                           <uforeandel_aarsverk>0.13320561</uforeandel_aarsverk>
                           <kvinneandel>0.92307692</kvinneandel>
                           <aktive>208</aktive>
                        </SUBTABLE3>
                        <SUBTABLE3>
                           <tid_tekst>01.01.2011</tid_tekst>
                           <kunde>Hamar Kommune</kunde>
                           <RF_nr>0018</RF_nr>
                           <RF>Kommuner og bedrifter</RF>
                           <gjennomsnittsalder>45.2209654</gjennomsnittsalder>
                           <gj_pensjonsgrunnlag_pr_aktiv>298839.76</gj_pensjonsgrunnlag_pr_aktiv>
                           <pensjonsgrunnlag>535819690</pensjonsgrunnlag>
                           <gj_pensjonsgrunnlag_pr_aarsverk>365159.524</gj_pensjonsgrunnlag_pr_aarsverk>
                           <gj_aktuell_deltid>0.81838139</gj_aktuell_deltid>
                           <uforeandel>0.19875776</uforeandel>
                           <uforeandel_aarsverk>0.15838171</uforeandel_aarsverk>
                           <kvinneandel>0.79364194</kvinneandel>
                           <aktive>1793</aktive>
                        </SUBTABLE3>
                        <SUBTABLE3>
                           <tid_tekst>01.01.2011</tid_tekst>
                           <kunde>Hamar Kommune</kunde>
                           <RF_nr>0023</RF_nr>
                           <RF>Folkevalgte</RF>
                           <gjennomsnittsalder>57.284052</gjennomsnittsalder>
                           <gj_pensjonsgrunnlag_pr_aktiv>694500</gj_pensjonsgrunnlag_pr_aktiv>
                           <pensjonsgrunnlag>694500</pensjonsgrunnlag>
                           <gj_pensjonsgrunnlag_pr_aarsverk>694500</gj_pensjonsgrunnlag_pr_aarsverk>
                           <gj_aktuell_deltid>1</gj_aktuell_deltid>
                           <uforeandel>0</uforeandel>
                           <uforeandel_aarsverk>0</uforeandel_aarsverk>
                           <kvinneandel>0</kvinneandel>
                           <aktive>1</aktive>
                        </SUBTABLE3>
                     </TABLE>
                  </axis2ns24:Value>
               </axis2ns23:_WEBOUT>
            </axis2ns22:Streams>
         </m:pensjonsdatatilEAWResult>
      </m:pensjonsdatatilEAWResponse>
   </soapenv:Body>
</soapenv:Envelope>

What I want to do is to validate (in SoapUI) that given the ID in the request:

<pen:forsikringstNr>00403001</pen:forsikringstNr>

The response should be the response with the values i.e.

<tid_tekst>01.01.2011</tid_tekst>

in the subtable

<SUBTABLE3>
                           <tid_tekst>01.01.2011</tid_tekst>
                           <kunde>Hamar Kommune</kunde>
                           <RF_nr>0018</RF_nr>
                           <RF>Kommuner og bedrifter</RF>
                           <gjennomsnittsalder>45.2209654</gjennomsnittsalder>
                           <gj_pensjonsgrunnlag_pr_aktiv>298839.76</gj_pensjonsgrunnlag_pr_aktiv>
                           <pensjonsgrunnlag>535819690</pensjonsgrunnlag>
                           <gj_pensjonsgrunnlag_pr_aarsverk>365159.524</gj_pensjonsgrunnlag_pr_aarsverk>
                           <gj_aktuell_deltid>0.81838139</gj_aktuell_deltid>
                           <uforeandel>0.19875776</uforeandel>
                           <uforeandel_aarsverk>0.15838171</uforeandel_aarsverk>
                           <kvinneandel>0.79364194</kvinneandel>
                           <aktive>1793</aktive>
                        </SUBTABLE3>

My initial problem is that the response contains 3 subtables, but your tip with using

//TABLE/SUBTABLE3[1]

Gave me one subtable in return.
Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.