Convert xml as string
i have a scenario where in i need to send an xml as a tag content in a SOAP request message to a webservice for example
<arg_1><xml version开发者_开发问答="1.0" encoding="UTF-8"?><sometag><somemoretag>abcd</somemoretag></sometag></arg_1></code>
arg_1 happens to be an String parameter to a webservice. So i bring in a CDATA section for this
<arg_1><![CDATA[<xml version="1.0" encoding="UTF-8"?><sometag><somemoretag>abcd</somemoretag></sometag>]]></arg_1>
But this keeps throwing me an exception
org.xml.sax.SAXException: WSWS3084E: Error: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize. Message being parsed:
I keep getting this exception. Has anyone seen this before??
There are a couple of ways you could handle this -
- Remove the XML Prolog and insert the original XML document into the content of an element in the other document.
<arg_1><sometag><somemoretag>abcd</somemoretag></sometag></arg_1>
- Escape the the original XML document like you would any other text content and insert the resulting text into the content of an element.
<arg_1><sometag><somemoretag>abcd</somemoretag></sometag></arg_1>
I had faced similar issue , wherein my xml was not inside the CDATA properly. For the tags to be treated as String you must use as the below:
<![CDATA[ ---your xml---- ]]>
However you have not used the ? before the xml version. The tag should be
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
In your case its <xml version="1.0" encoding="UTF-8" standalone="yes"?>
.
精彩评论