views:

25

answers:

1

Hello,

I am getting validation errors such as: "No processing instruction starts with 'xml...." when I try to validate my code before I put it into the 3rd party app I'm using. How do I send a soap message with Javasript that is embedded on an XSL page without getting this error ? Here is the code in question:

<script language="javascript">

 function test1(newSymbol){

 var symbol = newSymbol;  
 var xmlhttp = new XMLHttpRequest(); 

 xmlhttp.open("POST", "http://www.webservicex.net/stockquote.asmx?op=GetQuote",true); 
 xmlhttp.onreadystatechange=function() { 
  if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) { 
     alert(xmlhttp.responseText); 
   // http://www.terracoder.com convert XML to JSON  
   var json = XMLObjectifier.xmlToJSON(xmlhttp.responseXML); 
   var result = json.Body[0].GetQuoteResponse[0].GetQuoteResult[0].Text; 
   // Result text is escaped XML string, convert string to XML object then convert      to      JSON object 
   json = XMLObjectifier.xmlToJSON(XMLObjectifier.textToXML(result)); 
   alert(symbol + ' Stock Quote: $' + json.Stock[0].Last[0].Text + '\n' + 'Company      Name: ' + json.Stock[0].Name[0].Text);  
   document.getElementById('price').innerHTML = json.Stock[0].Last[0].Text;
   document.getElementById('name').innerHTML = json.Stock[0].Name[0].Text;

   }
   else if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status != 200) {
   alert('Server Issue');

   } 
 } 
 xmlhttp.setRequestHeader("SOAPAction", "http://www.webserviceX.NET/GetQuote"); 
 xmlhttp.setRequestHeader("Content-Type", "text/xml"); 
 var xml = '<?xml version="1.0" encoding="utf-8"?>' + 
  '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' + 
                 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' + 
                 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;' +  
    '<soap:Body> ' + 
      '<GetQuote xmlns="http://www.webserviceX.NET/"&gt; ' + 
        '<symbol>' + symbol + '</symbol> ' + 
      '</GetQuote> ' + 
    '</soap:Body> ' + 
  '</soap:Envelope>'; 
 xmlhttp.send(xml); 
 }

 </script>

Im getting the error on the var xml = line right after I declare the soap headers.

Thanks for your help with this! :)

A: 

Just remove the XML declaration: it is not necessary in this case, because the version and encoding pseudo attributes specify the default values -- 1.0 and utf-8.

Dimitre Novatchev
So I figured out that I could use the CDATA tags for the SOAP message string itself and it worked. However, now I am getting a "Access is denied" error at my xmlhttp.open(....) line. I have already enabled IEs misc "allow cross domain access". This code is calling from an Https domain to a nonsecure domain...Is this why?.
Lucas