The data flow getting failure in this line
xmlError = doc.parseError();
if(xmlError && xmlError.errorCode() != 0)
{
throw error(strFmt("XML Error: %1", xmlError.reason()));
}
May I know what might me the reason? am fetching the data from web URL.
Here is the full code.
public static void main(Args _args)
{
System.Net.HttpWebResponse response = null;
System.Net.WebException webException = null;
CLRObject webResponse = null;
str errorString;
URLBase url = "Mr URL";
const int batchSize = 1024;
str responseData;
XMLDocument XMLdoc;
int i,CountItemtags;
doc = new XmlDocument();
try
{
System.Net.HttpWebRequest request = null;
request = System.Net.WebRequest::Create(url) as System.Net.HttpWebRequest;
// If required by the server, set the credentials.
//request.Credentials = CredentialCache.DefaultCredentials;
webResponse = request.GetResponse();
response = webResponse as System.Net.HttpWebResponse;
}
catch (Exception::CLRError)
{
System.Exception exception = ClrInterop::getLastException();
if (exception)
{
CLRObject clrExceptionMessage = exception.get_message();
errorString = CLRInterop::getAnyTypeForObject(clrExceptionMessage);
exception = exception.get_InnerException();
while(exception)
{
if (exception is System.Net.WebException)
{
// There is a response body in the answer. This body will be attached in log.
webException = exception as System.Net.WebException;
webResponse = webException.get_Response();
response = webResponse as System.Net.HttpWebResponse;
}
clrExceptionMessage = exception.get_Message();
errorString += "\n" + CLRInterop::getAnyTypeForObject(clrExceptionMessage);
exception = exception.get_InnerException();
}
}
}
if (response)
{
System.IO.Stream receiveStream = response.GetResponseStream();
str contentEncoding = response.get_ContentEncoding();
System.Text.Encoding encode;
if (contentEncoding)
{
encode = System.Text.Encoding::GetEncoding(contentEncoding);
}
else
{
encode = new System.Text.UTF8Encoding();
}
System.IO.StreamReader readStream = new System.IO.StreamReader(receiveStream, encode);
System.Char[] read = new System.Char[batchSize]();
int countRead = readStream.Read(read, 0, batchSize);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.String readString;
while (countRead > 0)
{
readString = new System.String(read, 0, countRead);
sb.Append(readString);
countRead = readStream.Read(read, 0, batchSize);
doc.loadxml(sb.ToString());
// Verify XML Document Structure
xmlError = doc.parseError(); -- here itself code getting failed.
if(xmlError && xmlError.errorCode() != 0)
{
throw error(strFmt("XML Error: %1", xmlError.reason()));
}
// Get the root element and its child nodes
nodeScript = doc.getNamedElement("XMLScript");
xmlScriptList = nodeScript.childNodes();
for(i=0; i < xmlScriptList.length(); i++)
{
nodeProject = xmlScriptList.item(i);
xmlProjectList = nodeProject.childNodes();
info("### Project information: ");
// Print out node and attribute values
info(strFmt("XML Document Version: %1", nodeScript.getAttribute("Version")));
info(strFmt("Project Name: %1", nodeProject.getAttribute("Name")));
info(strFmt("Format: %1", nodeProject.getNamedElement("Format").text()));
info(strFmt("PrintSetup (innerXML): %1", nodeProject.getNamedElement("PrintSetup").innerXml()));
info(strFmt("Printer (text): %1 OR Printer (innerText): %2",
nodeProject.getNamedElement("PrintSetup").getNamedElement("Printer").text(),
nodeProject.getNamedElement("PrintSetup").innerText()));
// Loop through the repeating nodes
info("### Notes: ");
for (j=2; j < xmlProjectList.length(); j++)
{
nodeNote = xmlProjectList.item(j);
info(strFmt("ID: %1, Date: %2", nodeNote.getAttribute("ID"), nodeNote.getAttribute("Date")));
info(strFmt("To: %1", nodeNote.getNamedElement("To").text()));
info(strFmt("Body: %1", nodeNote.getNamedElement("Body").text()));
}
}
}
readStream.Close();
responseData = sb.ToString();
response.Close();
info(responseData);
}
}
Error Code:
'XML Error: Exception has been thrown by the target of an invocation.'