Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Unanswered

Reading xml over url gives error

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();
}


}

  • atsik Profile Picture
    atsik 10 on at
    RE: Reading xml over url gives error

    removing ufff -s fixed half data, but something is still blocking

  • atsik Profile Picture
    atsik 10 on at
    RE: Reading xml over url gives error

    xmlDoc.load(xmlUrl);  xmldoc will remain empty

  • Martin Dráb Profile Picture
    Martin Dráb 225,490 Super User on at
    RE: Reading xml over url gives error

    Maybe someone gives you an advice if you tell us more about your problem than just "it's not working".

  • atsik Profile Picture
    atsik 10 on at
    RE: Reading xml over url gives error

    simplest solution is not working. not sure about HttpClient  how to use it

  • Martin Dráb Profile Picture
    Martin Dráb 225,490 Super User on at
    RE: Reading xml over url gives error

    You seem to be focusing on a wrong piece of code. If xmlDocumentResponse doesn't contain correct data, there is no point in trying to use it. The problem is in how you're getting the value for xmlDocumentResponse.

    I don't know why you're using the COM object. I've never done and I would avoid it, even if it worked.

    The simplest solution may be loading the document directly from a URL. Give it a try:

    xmlDoc.load(xmlUrl);

    Alternatively you could download the file with HttpClient or something.

  • atsik Profile Picture
    atsik 10 on at
    RE: Reading xml over url gives error

    any ideas how to fix?

  • Martin Dráb Profile Picture
    Martin Dráb 225,490 Super User on at
    RE: Reading xml over url gives error

    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
    atsik 10 on at
    RE: Reading xml over url gives error

    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
    Martin Dráb 225,490 Super User on at
    RE: Reading xml over url gives error

    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
    atsik 10 on at
    RE: Reading xml over url gives error

    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?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans