Reading XML file from HTTP
AitorEG
Member Posts: 342
Hi everyone,
I'm finding an issue with the objects involving ain a routine i am cerating for reading an XMl file from an HTTP request. here is the part of the code:
The code fails when it tries to create the xmlNodeList variable, with this error:

I have to say that the HTTP call has a response, that can be seen with the Fiddler (courtesy of @Slawek_Guzek )
What I'm doing wrong in the creation of the NodeList?
Thank you very much
I'm finding an issue with the objects involving ain a routine i am cerating for reading an XMl file from an HTTP request. here is the part of the code:
IF ISCLEAR(locautXmlDoc) THEN
CREATE(locautXmlDoc,FALSE,TRUE);
locautXmlDoc.load(XMLHTTP.responseXML);
CREATE(xmlNodeList, FALSE, TRUE);
xmlNodeList := locautXmlDoc.getElementsByTagName('CONNUMBER');
The code fails when it tries to create the xmlNodeList variable, with this error:

Cannot create an instance for the automation server with CLSIF ={XXX-XXXX}
I have to say that the HTTP call has a response, that can be seen with the Fiddler (courtesy of @Slawek_Guzek )
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><document><CREATE><CONREF>15D</CONREF><CONNUMBER>GE158487071ES</CONNUMBER><SUCCESS>Y</SUCCESS></CREATE></document>
What I'm doing wrong in the creation of the NodeList?
Thank you very much
0
Best Answer
-
As I've mentioned, look inside the C6224 and see how the things are done in there.
Just analyse the functions available, it will give you answers. Look for FindNode in the first place.
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035
Answers
-
Now, I'm Trying to do this (without doing the CREATE for the nodelist):
locautXmlDoc.load(XMLHTTP.responseXML); xmlNodeList := locautXmlDoc.getElementsByTagName('CONNUMBER'); xmldomElem1 := xmlNodeList.item(0); conNote := xmldomElem1.text();
And I get this error:
Interrupt in error message: The instance for the automation variable has not been created
0 -
You can’t create automation variable on the server. You must create it client side or use .NET library server side.0
-
Look into Codeunit 6224 XML DOM Management. You will find there a bunch of functions dealing with XML, files all .NET based.
Use these functions/variables in your solution.
For example, rather thanIF ISCLEAR(locautXmlDoc) THEN CREATE(locautXmlDoc,FALSE,TRUE); locautXmluDoc.load(XMLHTTP.responseXML);
tryIF NOT C6224.LoadXMLDocumentFromText(XMLHTTP.responseXML, XMLDocument) THEN HandleError()...
The call wll return the XMLDocument var, which is a .NET type XML objectSlawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
AdrianAkers wrote: »You can’t create automation variable on the server. You must create it client side or use .NET library server side.
I've already created some automation variables like this, changing the "RunOnClient" paremeter to "YES", but in this case, It's not posible0 -
Slawek_Guzek wrote: »Look into Codeunit 6224 XML DOM Management. You will find there a bunch of functions dealing with XML, files all .NET based.
Use these functions/variables in your solution.
For example, rather thanIF ISCLEAR(locautXmlDoc) THEN CREATE(locautXmlDoc,FALSE,TRUE); locautXmluDoc.load(XMLHTTP.responseXML);
tryIF NOT C6224.LoadXMLDocumentFromText(XMLHTTP.responseXML, XMLDocument) THEN HandleError()...
The call wll return the XMLDocument var, which is a .NET type XML object
Thanks, I'll try with this approach, Really appreciated!!!
edit: In this sentence, I have a compilation error:XMLDomMgmt.LoadXMLDocumentFromText(XMLHTTP.responseXML, locautXmlDoc);
locautXmlDoc DotNet System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
"Cannot convert type because one of the operators has an invalid type
Text := Automation"
Which type must the objetcs be?
0 -
"XMLHTTP.responseText" returns correctly the response value of the request, I can confirm that, The issue is to load it on an XML file, to later get the value of the required node.0
-
LoadXMLDocumentFromText accepts Text in the first parameter, so perhaps you should do this call in 2 steps:ResponseXmlText := XMLHTTP.responseText; IF NOT C6224.LoadXMLDocumentFromText(ResponseXmlText , XMLDocument) THEN HandleError()...
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Slawek_Guzek wrote: »LoadXMLDocumentFromText accepts Text in the first parameter, so perhaps you should do this call in 2 steps:
ResponseXmlText := XMLHTTP.responseText; IF NOT C6224.LoadXMLDocumentFromText(ResponseXmlText , XMLDocument) THEN HandleError()...
Thanks, I've tried that, But now, my error is when tryng to get the elemnt from the XML. I'm doing this:xmlNodeList := locautXmlDoc.GetElementsByTagName('CONNUMBER'); xmldomElem1 := xmlNodeList.item(0); conNote := xmldomElem1.text();
But it says that assignment is not allowed for "xmlNodeList ". Should I change the type of the variable? What types are the bests for doin g this issue? I'm getting a mess whit DOMDocument, XMLDocuments....
0 -
As I've mentioned, look inside the C6224 and see how the things are done in there.
Just analyse the functions available, it will give you answers. Look for FindNode in the first place.
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-035 -
I'm using the FindNodeTExt function:
ResponseText := XMLHTTP.responseText; XMLDomMgmt.LoadXMLDocumentFromText(ResponseText, locautXmlDoc); conNote := XMLDomMgmt.FindNodeText(locautXmlDoc,'//DOCUMENT/CREATE/CONNUMBER');
But when I run the app, I see the error:
Cannot serialize an instance of the .Net framework object: ........
I've found this type of erros quite a lot while developing this application, and I fixed it changing the "RunOnClient" parameter on the DotNet variables. But now it's not working. When debbuging, I can see this:
It is failing in the 6224 CU. I've generated and made the HTTP request with Automation instead of DOTNet variables because of this issue
How can this problem be solved?0 -
Solved! i had to change all the RunOnClient propertis, not just in the 6224CU, but also in my develepment, where I forgot one of them.Thanks!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
