Forum Discussion

Norinth's avatar
12 years ago

error: Unexpected element: CDATA on Transfer / XmlHolder

Hi,

I currently have a response that returns the following Raw XML on a REST service:
<data contentType="application/xml; charset=utf-8" contentLength="857">
<![CDATA[<Main publisher="mss.cto." publicationTime="2013-11-21T14:13:37" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn::metadata:2008">
<Description>
<LocationTable>
<Schedule IDRef="_Test_1"/>
<Schedule IDRef="_Test_2"/>
</LocationTable>
<InformationTable>
<Information Id="_Test_1">
<Name length="medium"> Test 1</Name>
<URL>00a2</URL>
<Genre href="urn::metadata:cs:CS:2008:04"/>
</Information>
<Information Id="_Test_2">
<Name length="medium"> Test 2</Name>
<URL>00a3</URL>
<Genre href="urn::metadata:cs:CS:2008:04"/>
</Information>
</InformationTable>
</Description>
</Main>]]>
</data>


The whole contents have a CDATA flag applied, which I would need to remove beforehand to carry on. I've used the SubmitListener.afterSubmit Event at a project level with the usual code (mentioned in the CDATA guide in the site):
def content = submit.response.responseContent
content = content.replaceAll( "<!\\[CDATA\\[", "" )

content = content.replaceAll( "]]>", "" )

log.info "afterSubmit - "+content

submit.response.responseContent = content


But the replacement will only work for anything inside Main (inclusive). For example:
- a content = content.replaceAll( "data", "" ) or content = content.replaceAll( "contentType", "" ) does nothing.
- a content = content.replaceAll( "Main", "water" ) will replace correctly.

Ergo, I can never remove the CDATA tag.
----------------------------------------------
I've also tried to use a script and even Property Transfers to store the result into a property.
- Transfering the response to a property works, and I don't see the CDATA there afterwards (only from "Main" onwards, which might hint why the replace CDATA above fails to work).

Script:

// allServices is the step name
def inputHolder = "allServices#Response"
def holderRawReq = groovyUtils.getXmlHolder(inputHolder)


This returns a "org.apache.xmlbeans.XmlException: error: Unexpected element: CDATA error at line:x", the getXmlHolder line.

The same happens if I try to use an XPath expression in a 2nd Property Transfer, with Source as the Property I started with.