You need to sign in to do that
Don't have an account?
Yashavant
System.XmlException: ParseError at [row,col]:[1,1] Message: Content is not allowed in prolog.
HI,
I am calling one web service and getting response in XML and while iterating through that XML i got below exception
System.XmlException: ParseError at [row,col]:[1,1] Message: Content is not allowed in prolog.
Can anybody help me?
Thanks
Yash
I am calling one web service and getting response in XML and while iterating through that XML i got below exception
System.XmlException: ParseError at [row,col]:[1,1] Message: Content is not allowed in prolog.
Code:
HttpRequest req = new HttpRequest(); String url='abaccc'; req.setEndpoint(url); req.setMethod('GET'); // Send the request, and return a response HttpResponse res = h.send(req); XmlStreamReader reader = res.getXmlStreamReader(); // Read through the XML while(reader.hasNext()) { System.debug('Event Type:' + reader.getEventType()); if (reader.getEventType() == XmlTag.START_ELEMENT) { System.debug('Local name :'+reader.getLocalName()); } reader.next();// Getting exception at this line. }
Can anybody help me?
Thanks
Yash
Hey Yash,did you get solution for this????
Occasionally the XML stream that is returned has a "hidden" character before the first "<". In this case you will receive the ParseError at [row,col]:[1,1] Message: Content is not allowed in prolog error message. In order to move past this hidden character and get to the xml you are trying to parse use the following:
//Obviously do your setup before this point
//Send the request and return a response
HttpResponse res = h.send(req);
result = res.getBody(); //Get the result
result = result.substring(1); //Move past the first character but keep the remainder of the string (which is the XML you want)
This worked for me.
Just encountered the same error, in my case, I used next() method initially in traversing the StreamReader else to move to the next node, before doing the loop --
XmlStreamReaderVariable.next();