I need help parsing this string

JLeePlnr
Member Posts: 26
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!!!!
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
-
Look into Codeunit 6224 XML DOM Management, you will find there a few functions which will help you to extract required attributes:
c6224.LoadXMLDocumentFromText(XMLDoc,...) IF c6224.FindNode(XMLDoc, '/ncresponse/@NCERRORPLUS', XMLNode) THEN NCERRORPLUSValue = XMLNode.InnerText; IF c6224.FindNode(XMLDoc, '/ncresponse/@NCERROR', XMLNode) THEN NCERRORValue = XMLNode.InnerText;
You will find all required variable types in the codeunit too (in function parameters definitions)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: »Look into Codeunit 6224 XML DOM Management, you will find there a few functions which will help you to extract required attributes:
c6224.LoadXMLDocumentFromText(XMLDoc,...) IF c6224.FindNode(XMLDoc, '/ncresponse/@NCERRORPLUS', XMLNode) THEN NCERRORPLUSValue = XMLNode.InnerText; IF c6224.FindNode(XMLDoc, '/ncresponse/@NCERROR', XMLNode) THEN NCERRORValue = XMLNode.InnerText;
You will find all required variable types in the codeunit too (in function parameters definitions)
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!
0 -
Hi,
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
======
0 -
Sorry, I did miss that this is the NAV/Navision Classic Client forum.
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:IF FindNode(XmlDoc2, '/ncresponse/@NCERROR', XmlNode) THEN BEGIN NodeValueTxt := XmlNode.nodeValue; nodeNameTxt := XmlNode.nodeName; END
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: »Sorry, I did miss that this is the NAV/Navision Classic Client forum.
Try to examine other properties of the XmlNode var, maybe XmlNode.nodeValue, XmlNode nodeName to see what is returned:IF FindNode(XmlDoc2, '/ncresponse/@NCERROR', XmlNode) THEN BEGIN NodeValueTxt := XmlNode.nodeValue; nodeNameTxt := XmlNode.nodeName; END
I tried this, and still giving me an empty data on both
NodeValueTxt := XmlNode.nodeValue;
nodeNameTxt := XmlNode.nodeName;
Any more suggestion?0 -
Does the XPath validator website returns expected attribute name/value pair when you paste the XML and the /ncresponse/@NCERROR' XPath expression?
If yes you may try to retrieve XmlNode.attributes list and then loop through all of themSlawek 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: »Does the XPath validator website returns expected attribute name/value pair when you paste the XML and the /ncresponse/@NCERROR' XPath expression?
This is the XPATH Result
Attribute='NCERROR=50001113'
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!!!0 -
Can someone help me on this please?0
-
This post has examples https://forum.mibuso.com/discussion/47694/test-each-attribute-of-an-xml-file0
-
This post has examples https://forum.mibuso.com/discussion/47694/test-each-attribute-of-an-xml-file
Thanks a lot KarenH, I'll try it out.0 -
===
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?
0 -
The "Attributes" property is a list of objects. Try using the same type for your XMLAttributes var as you have used for the XMLNodeList var.Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Hi Slawek, appreciate your response
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?
0 -
You have another examples in the link then @Karenh sent you. Have you tried them? Have you tried to google arond and read some MS XML documentation to see what you may need?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: »You have another examples in the link then @Karenh sent you. Have you tried them? Have you tried to google arond and read some MS XML documentation to see what you may need?
Yes, I have Slawek and I am still unable to make it work.0 -
Perhaps you need to install MS XML 6.0 on your machine.
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 readableSlawek 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: »Perhaps you need to install MS XML 6.0 on your machine.
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
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!!!!
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
- 320 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