Forum Discussion

Sphujidhwaj's avatar
Sphujidhwaj
Contributor
9 years ago

XQuery Match Configuration or Groovy Script

I have an XML Response in SOAP which has the below format 

<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <NewDataSet xmlns="">
    <Status diffgr:id="Status12" msdata&colon;rowOrder="11">
    <id>28</id>
    <name>Review</name>
    <categoryId>3</categoryId>
    <assignrule>P</assignrule>
    <ismoveAssign>0</ismoveAssign>
    <isActive>1</isActive>
    </Status>
    </NewDataSet>
</diffgr:diffgram>

 I have to extract the statuses which are more than 500 and I am trying to extract the same by using XQuery Match 

 

<Result>
{
    for $x in //*[local-name() = 'NewDataSet']/*[local-name()='Status']/*[local-name()='name']

    return <name> string ($x) </name>
}
</Result>

 But in the output I am able to find only 

 <Result>
<name>string ($x)</name>
<name>string ($x)</name>

</Result>

 

Please assist me in this regard. Is my XQuery Correct or should I use Script Assertion?

 

Please find below the XML response and it is very huge consisting of nearly 4000 lines.

 

16 Replies

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    You could certainly do this with a Script Assertion, but in terms of XQuery is what you're looking for something like this:

     

    1) You have something like:

    <diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
        <NewDataSet xmlns="">
        <Status diffgr:id="Status12" msdata&colon;rowOrder="11">
        <id>28</id>
        <name>Review1</name>
        <categoryId>3</categoryId>
        <assignrule>P</assignrule>
        <ismoveAssign>0</ismoveAssign>
        <isActive>1</isActive>
        </Status>
    <Status diffgr:id="Status12" msdata&colon;rowOrder="11">
        <id>28</id>
        <name>Review2</name>
        <categoryId>3</categoryId>
        <assignrule>P</assignrule>
        <ismoveAssign>0</ismoveAssign>
        <isActive>1</isActive>
        </Status>
    <Status diffgr:id="Status12" msdata&colon;rowOrder="11">
        <id>28</id>
        <name>Review3</name>
        <categoryId>3</categoryId>
        <assignrule>P</assignrule>
        <ismoveAssign>0</ismoveAssign>
        <isActive>1</isActive>
        </Status>
        </NewDataSet>
    </diffgr:diffgram>

    2) You apply XQuery:

    <Result>
    {
        for $x in //Status
    
        return <name> string {data($x/name/text())} </name>
    }
    </Result>

    3) And get:

    <?xml version="1.0" encoding="UTF-8"?>
    <Result>
       <name> string Review1</name>
       <name> string Review2</name>
       <name> string Review3</name>
    </Result>

    ?

     

    Let me know,

     

    Cheers,

    Rupert

     

    • Sphujidhwaj's avatar
      Sphujidhwaj
      Contributor
      <diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
          <NewDataSet xmlns="">
          <Status diffgr:id="Status1" msdata&colon;rowOrder="11">
          <id>28</id>
          <name>Review1</name>
          <categoryId>3</categoryId>
          <assignrule>P</assignrule>
          <ismoveAssign>0</ismoveAssign>
          <isActive>1</isActive>
          </Status>
      <Status diffgr:id="Status2" msdata&colon;rowOrder="11">
          <id>28</id>
          <name>Review2</name>
          <categoryId>3</categoryId>
          <assignrule>P</assignrule>
          <ismoveAssign>0</ismoveAssign>
          <isActive>1</isActive>
          </Status>
      <Status diffgr:id="Status3" msdata&colon;rowOrder="11">
          <id>28</id>
          <name>Review3</name>
          <categoryId>3</categoryId>
          <assignrule>P</assignrule>
          <ismoveAssign>0</ismoveAssign>
          <isActive>1</isActive>
          </Status>
          </NewDataSet>
      </diffgr:diffgram>

       

       

      The StatusID also keeps changing here.. 

      • rupert_anderson's avatar
        rupert_anderson
        Valued Contributor

        OK, so it does, do you exepect to see the id in the output, thats not outlined in the original post? If so, please provide a sample of exactly what you expect in terms of the resulting XML and then I might be able to help.