0

I am using the following code to get a result but for some reason I am getting this error: Error on line 1: Content is not allowed in prolog. (line 134, file "Code") which in this case is

var xmlResult = XmlService.parse(result).getRootElement();

var xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v1=\"http://openclinica.org/ws/studySubject/v1\" xmlns:bean=\"http://openclinica.org/ws/beans\">"
       +"<soapenv:Header>"
        +"<wsse:Security soapenv:mustUnderstand=\"1\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
        +"<wsse:UsernameToken wsu:Id=\"UsernameToken-27777511\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"
        +"<wsse:Username>yyyy</wsse:Username>"
        +"<wsse:Password>xxxxx</wsse:Password>"
        +"</wsse:UsernameToken>"
        +"</wsse:Security>"
       +"</soapenv:Header>"
       +"<soapenv:Body>"
          +"<v1:listAllByStudyRequest>"
             +"<bean:studyRef>"
                +"<bean:identifier>PROSPER2</bean:identifier>"
             +"</bean:studyRef>"
          +"</v1:listAllByStudyRequest>"
       +"</soapenv:Body>"
    +"</soapenv:Envelope>";


      var options =
      {
        "method" : "post",
        "contentType" : "text/xml",
        "payload" : xml
      };

      var result = UrlFetchApp.fetch("http://89.221.253.174:8080/OpenClinica-ws/ws/studySubject/v1/studySubjectWsdl.wsdl", options);

      var xmlResult = XmlService.parse(result).getRootElement();


      Logger.log(xmlResult);

Any idea why this is not working, I am using google apps script to execute this code;

pranvera hoti
  • 107
  • 3
  • 15

1 Answers1

0

You may refer with this thread. Check the xml file whether it has any junk character like this �. It's also stated here that this error is probably related to a byte order mark (BOM) prior to the actual XML content. You need to parse the returned String and discard the BOM, so SAXParser can process the document correctly.

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59