0

I have a string object that contains XML (including body and metadata). When I try to parse it I get the following error:

org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog

I tried to use My_XML.getBody() function but it didn't help. I need some help with how to edit my XML so it will be allowed.

Example XML

{"body": <<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TccSubscriptionData xmlns="tcc.generated.com">
    <MessageKey>
        <MessageKey>12</MessageKey>
        <Receiver>asd</Receiver>
        <Timestamp>2018-06-20T14:33:22.968+02:00</Timestamp>
        <ResponseType>sdf</ResponseType>
        <CorrelationId>0</CorrelationId>
    </MessageKey>
</TccSubscriptionData>
, "metadata": {"field1": "aaa", "field2": 123, "field3": aaa, "field4": "aaa", "field5": 123, "field6": {"field7":"aaa","field8":"a12d","field9":"aaa"}}}
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Roei Givati
  • 39
  • 1
  • 5
  • If you are trying to parse the exact content as you posted, `{"body": <` is a prolog that is not XML compatible, and neither is the `, "metadata"...` stuff at the end. An XML parser can parse only XML, not a combination of JSON and XML. – M. le Rutte Jun 24 '18 at 12:27

1 Answers1

0

Your example XML is embedded within JSON, and your JSON is not well-formed.

In order to represent your XML as a string, you'll have to surround it with ", and you'll have to replace the " characters used as XML markup with ' characters or escape them as \". You'll also have to remove the line breaks or replace them with \\n.

Then, of course, as M. le Rutte comments, be sure that you're providing the XML parser with the XML extracted from the JSON, not the JSON message itself.

kjhughes
  • 106,133
  • 27
  • 181
  • 240