Forum Discussion

Perchishka's avatar
Perchishka
Occasional Contributor
7 years ago
Solved

Groovy loop for parsing - XML Content is not allowed in prolog

Hello!

Could you help me please.

 I have a JDBC Request and response looks like:

<Results>
    <ResultSet fetchSize="0">
        <Row rowNumber="1">
            <PS_CONTENT_ONDEMAND.EXTERNAL_CODE>f538de04</PS_CONTENT_ONDEMAND.EXTERNAL_CODE>
            <PS_CONTENT_ONDEMAND.SUBSCRIBE_PARAMS_ID>8765</PS_CONTENT_ONDEMAND.SUBSCRIBE_PARAMS_ID>
            <PS_CONTENT_ONDEMAND.DATE>2017-03-15 00:00:00.705</PS_CONTENT_ONDEMAND.DATE>
            <PS_SUBSCRIBE_PARAMS.URL>http://stk.o4evidec.ru/?alias=mtsby_dance</PS_SUBSCRIBE_PARAMS.URL>
            <PS_SUBSCRIBE_PARAMS.ID>8765</PS_SUBSCRIBE_PARAMS.ID>
        </Row>
        <Row rowNumber="2">
            <PS_CONTENT_ONDEMAND.EXTERNAL_CODE>2273851</PS_CONTENT_ONDEMAND.EXTERNAL_CODE>
            <PS_CONTENT_ONDEMAND.SUBSCRIBE_PARAMS_ID>8766</PS_CONTENT_ONDEMAND.SUBSCRIBE_PARAMS_ID>
            <PS_CONTENT_ONDEMAND.DATE>2017-03-15 06:00:00.944</PS_CONTENT_ONDEMAND.DATE>
            <PS_SUBSCRIBE_PARAMS.URL>http://intra.mobile-content.a1s/alias/tele2_dema</PS_SUBSCRIBE_PARAMS.URL>
            <PS_SUBSCRIBE_PARAMS.ID>8766</PS_SUBSCRIBE_PARAMS.ID>
        </Row>

I need to create a loop to set each node :

PS_CONTENT_ONDEMAND.EXTERNAL_CODE

as property in  that testCase

 

At first, I decided to create a  script assertion with a simple loop  to check how it works :

def parsedXml = new XmlSlurper().parseText("context.ResponseasXML")
parsedXml.Row.each { Row ->
println "Row index: ${Row.@rowNumber}"
Row.children().each{ tag -> println " ${tag.name()}: ${tag.text()}"
  }
}

But I have an error :

Content is not allowed in prolog

What should i do?

 

  • Hi Perchishka,

     

    The error is caused by the quotes around "context.ResponseasXML" - this way it's treated as a literal string instead of an object property. Remove the quotes here.

     

    Also replace println with SoapUI's log.info.


    Also

    parsedXml.Row.each { ...

    should be

    parsedXml.ResultSet.Row.each { ...

2 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi Perchishka,

     

    The error is caused by the quotes around "context.ResponseasXML" - this way it's treated as a literal string instead of an object property. Remove the quotes here.

     

    Also replace println with SoapUI's log.info.


    Also

    parsedXml.Row.each { ...

    should be

    parsedXml.ResultSet.Row.each { ...
    • Perchishka's avatar
      Perchishka
      Occasional Contributor

      Thank you very much!:smileyhappy:

      It works