Hi guys,
I need help in parsing the below mentioned string. This string is a .xml response from the back.
<?xml version="1.0"?>
<ncresponse NCERRORPLUS="This order has already been processed." ALIAS="ABC33557302" BRAND="American Express" PM="CreditCard" currency="GBP" amount="372.76" STATUS="0" ACCEPTANCE="test123456" NCERROR="50001113" NCSTATUS="0" PAYID="3035462606" orderID="2373653218"> </ncresponse>
I want to load this .xml file and capture the values of NCERRORPLUS, NCERROR, and NCSTATUS. I am going to use the return values on these fields to further control the sales order processing with credit cards.
Please help.
Thanks NAV gurus!!!!
0
Comments
You will find all required variable types in the codeunit too (in function parameters definitions)
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Hi,
I can't find this function in the c6224 LoadXMLDocumentFromText(XMLDoc,...). I also can't find the InnerText property on the XMLNode.
Did I miss something? I am using 2009 R2
Thanks!
I tried to do this but my NCErrorValue gave me empty data value.
Please help.
//=====
Variable:
XmlDoc2 Automation 'Microsoft XML, v6.0'.DOMDocument60
XmlDoc2.async := FALSE;
XmlDoc2.load(XMLHTTP.responseBody);
IF EXISTS(ReceiveFile) THEN ERASE(ReceiveFile);
XmlDoc2.save(ReceiveFile);
XmlDoc2.load(ReceiveFile);
IF FindNode(XmlDoc2, '/ncresponse/@NCERROR', XmlNode) THEN
NCErrorValue := XmlNode.text;
ERROR('NCErrorValue = %1',NCErrorValue);
//======
FindNode()
IF ISCLEAR(XMLRootNode) THEN
EXIT(FALSE);
IF NOT NormalCaseMode THEN
NodePath := UPPERCASE(NodePath);
FoundXMLNode := XMLRootNode.selectSingleNode(NodePath);
IF ISCLEAR(FoundXMLNode) THEN
EXIT(FALSE)
ELSE
EXIT(TRUE);
Variables:
======
XMLRootNode Automation 'Microsoft XML, 6.0'.IXMLDOMNode
NodePath Text 250
FoundXMLNode Automation'Microsoft XML,6.0'.IXMLDOMNode
======
The code looks pretty OK.
Use some XPath testing website, like this one to make sure that your XML (uploaded from ReceiveFile) is valid, and that the FindNode returns something, although me thinks that it does otherwise you would be getting errors on accessing XmlNode.text on an uninitialized automation var
Nb apart from debugging saving the XML into a file reloading it is not necessary.
Try to examine other properties of the XmlNode var, maybe XmlNode.nodeValue, XmlNode nodeName to see what is returned:
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
I tried this, and still giving me an empty data on both
NodeValueTxt := XmlNode.nodeValue;
nodeNameTxt := XmlNode.nodeName;
Any more suggestion?
If yes you may try to retrieve XmlNode.attributes list and then loop through all of them
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
If yes you may try to retrieve XmlNode.attributes list and then loop through all of them
Could you describe more detail on how to accomplish this?
Thanks for helping!!!
Thanks a lot KarenH, I'll try it out.
CREATE(XMLDoc2);
XMLDoc2.load(ReceiveFile);
XMLNodeList := XMLDomDoc.selectNodes('ncresponse');
XMLNodeCurr := XMLNodeList.nextNode();
XMLAttributes := XMLNodeCurr.attributes;
i := 0
WHILE i < XMLAttributes.length DO BEGIN
case XMLAttributes.item(i).nodeName of
'NCERROR': NCErrorValue := XMLAttributes.item(i).text;
end;
i += 1;
END;
=====
KarenH,
I mimic the same logic from the link but I got an this error
"You have specified an unknown variable
length
Define the variable under 'Global C/AL symbols."
It seems the var XMLAttributes is using a wrong Automation data type?
How can I fix this?
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
I changed the XMLAttributes to be the same with XMLNodeList var.
I got this error message when calling the function
Is there any other solution on solving this problem? Maybe load the .xml into a file and read it by using strpos until reach end of file?
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Yes, I have Slawek and I am still unable to make it work.
Export your object with your attempts to a text file and paste its contet here. If you don't want to paste the whole code include at least the bits you have tried (including the other version with and please include variables definition.
And please do use code formatting feature, it makes pasted code much more readable
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
I am finally able to resolve the problem using the link from @Karenh.
Thank you very much for your helps and response @Slawek_Guzek and @Karenh !!! I really appreciate it.
You guys rock!!!!