web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Reading xml over url gives error

(0) ShareShare
ReportReport
Posted on by 10

When trying to read xmldata over url I will get xml but  xmldocument.loadxml() reads only first line from response.

what is wrong?

code:

static void Job303(Args _args)
{

COM objXHTTP;

xml xmlDocumentOut;
url xmlUrl;
str xmlError;
str xmlDocumentResponse;
//#define.xmlhttp('MSXML2.XMLHTTP')
#define.serverXmlHttp('MSXML2.ServerXMLHTTP')


#define.xmlResolve(3000)
#define.xmlConnect(3000)
#define.xmlSend(3000)
#define.xmlReceive(3000)

interopPermission interopPermission;
int xxx;
XMLNode rootNode, bodyNode,bodyNode1,AttNode;
XMLNodeList bodyLines,childLine;
XMLElement xmlElement;
XMLNodeList _xmlNodelist;
XMLDocument XMLdoc = new XMLDocument();
str filename, nodeName,txtFile,strTxtRow;
str AttName;
int i,j,k;
boolean Valid;

;

xmlDocumentOut = ''; // Set your XML Doc
xmlUrl = 'mirpol.rzeszow.pl/.../itqty2022.xml'; // Set the URL


interopPermission = new InteropPermission(InteropKind::ComInterop);
InteropPermission.assert();

objXHTTP = new COM(#serverxmlHttp);
objXHTTP.settimeouts(#xmlResolve, #xmlConnect, #xmlSend, #xmlReceive);
objXHTTP.Open("POST", xmlUrl, False);
objXHTTP.setRequestHeader("Content-Type", "text/xml.");
objXHTTP.send(xmlDocumentOut);

xmlDocumentResponse = objXHTTP.responseText();


info(xmlDocumentResponse);
XMLDoc.loadxml(xmlDocumentResponse);

objXHTTP = null;

codeAccessPermission::revertAssert();

// XMLdoc.load(@"C:\temp\textIOtest.xml");

rootNode = xmldoc.documentElement();
nodeName = rootnode.baseName();
xmlElement = xmldoc.documentElement();
if(rootnode.hasChildNodes())
{
bodyLines = rootnode.childNodes();
}


}

I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    First of all, let me post your code once more, this time in the correct way. Please always use Insert > Code. Let me also throw away all the unused variables.

    COM objXHTTP;
    
    xml xmlDocumentOut = ''; // Set your XML Doc
    url xmlUrl = 'mirpol.rzeszow.pl/.../itqty2022.xml'; // Set the URL
    str xmlDocumentResponse;
    
    #define.serverXmlHttp('MSXML2.ServerXMLHTTP')
    
    #define.xmlResolve(3000)
    #define.xmlConnect(3000)
    #define.xmlSend(3000)
    #define.xmlReceive(3000)
    
    InteropPermission interopPermission;
    
    XMLDocument xmlDoc = new XMLDocument();
    XMLNode rootNode;
    XMLNodeList bodyLines;
    XMLElement xmlElement;
    str nodeName;
    ;
    
    interopPermission = new InteropPermission(InteropKind::ComInterop);
    interopPermission.assert();
    
    objXHTTP = new COM(#serverxmlHttp);
    objXHTTP.settimeouts(#xmlResolve, #xmlConnect, #xmlSend, #xmlReceive);
    objXHTTP.Open("POST", xmlUrl, False);
    objXHTTP.setRequestHeader("Content-Type", "text/xml.");
    objXHTTP.send(xmlDocumentOut);
    
    xmlDocumentResponse = objXHTTP.responseText();
    
    info(xmlDocumentResponse);
    xmlDoc.loadxml(xmlDocumentResponse);
    
    codeAccessPermission::revertAssert();
    
    rootNode = xmlDoc.documentElement();
    nodeName = rootnode.baseName();
    xmlElement = xmlDoc.documentElement();
    
    if (rootnode.hasChildNodes())
    {
    	bodyLines = rootnode.childNodes();
    }

    Now, what do you mean "reads only first line from response"? It loads the whole document, and the document must have just a single root node.

  • atsik Profile Picture
    10 on at

    XmlNode object not initialized.

    Stack trace

    (C)\Jobs\Job303 - line 42

  • atsik Profile Picture
    10 on at

    I tried to write xmldoc.xml out to a file and got only first line

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Now I'm completely confused. Does you code throw an exception or does it successfully return data, but less then you expect?

    What code do have at line 42?

  • atsik Profile Picture
    10 on at

    rootNode = xmlDoc.documentElement();

  • atsik Profile Picture
    10 on at

    wrote xmlDocumentResponse out to a test file via textio and tried to load it as file using  xmldocument.load() method and got same error, but if I save xml from browser manually then I can load it. I can't figure out what's wrong, but I guess some hidden characters perhaps?

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Then it can't be true that you "got only first line". Your code throws an exception before you manage to extract any data at all.

    Does xmlDocumentResponse variable contain valid XML? I doesn't seem to be the case.

  • atsik Profile Picture
    10 on at

    visually ok. And well i tried another url aswell and same problem. Can't select any nodes I guess LoadXML takes only first line from variable. <?xml version="1.0" encoding="windows-1250"?> and that's it.  Tried to take a substring, but no better results.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    All right, we've just found the problem. The root element can't be loaded, because there is no element at all. The document is empty.

  • atsik Profile Picture
    10 on at

    any ideas how to fix?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans