Skip to main content

Notifications

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


}

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

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

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

    xmlDoc.load(xmlUrl);  xmldoc will remain empty

  • Martin Dráb Profile Picture
    232,968 Most Valuable Professional 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
    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
    232,968 Most Valuable Professional 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
    10 on at
    RE: Reading xml over url gives error

    any ideas how to fix?

  • Martin Dráb Profile Picture
    232,968 Most Valuable Professional 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
    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
    232,968 Most Valuable Professional 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
    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?

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,190 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,968 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans