Escaping characters in XML for a SOAP request
 
            
                
                    AitorEG                
                
                    Member Posts: 342                
            
                        
            
                    Hi everyone,
I have a little issue generating an XML. At first look, it seems that the XML is OK, but I find problem when I try to make a request with it.
The XML should have a field like this:
I create the field in the XML like this:
At the first look, I open the XML file with the briowser, and seems to be fine:

But the issue is that, this XML file is sent in a request in text format, and if I open it with the editor, I can see this:
So that provokes a marshalling error in the web service. How can I add the character correctly? I've tried to scape them in different ways, but i can't find the correct approach.
Any hint will be really appreciated.
Thanks!
                
                I have a little issue generating an XML. At first look, it seems that the XML is OK, but I find problem when I try to make a request with it.
The XML should have a field like this:
<collectionDateTime><![CDATA[2017-12-14T08:10:00]]></collectionDateTime>
I create the field in the XML like this:
lvl2XMlNode := XMLDocOut.createNode(1,'collectionDateTime','');
ConsigmentXMlNode.appendChild(lvl2XMlNode);
DomTextNode := XMLDocOut.createTextNode('<![CDATA[2017-12-14T11:35:00]]>');
lvl2XMlNode.appendChild(DomTextNode);
At the first look, I open the XML file with the briowser, and seems to be fine:

But the issue is that, this XML file is sent in a request in text format, and if I open it with the editor, I can see this:
collectionDateTime><![CDATA[2017-12-14T11:35:00]]></collectionDateTime>
So that provokes a marshalling error in the web service. How can I add the character correctly? I've tried to scape them in different ways, but i can't find the correct approach.
Any hint will be really appreciated.
Thanks!
0                
            Best Answers
- 
            sorry, my bad. <![CDATA[]]> is valid XML. It just cannot be added as a regular node.
 check this:
 https://msdn.microsoft.com/en-us/library/system.xml.xmldocument.createcdatasection(v=vs.110).aspxSlawek Guzek
 Dynamics NAV, MS SQL Server, Wherescape RED;
 PRINCE2 Practitioner - License GR657010572SG
 GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-036
Answers
- 
            You cannot have < or > inside the node value, that's why it has been escaped
 This: 
 is invalid XML.
 Slawek Guzek
 Dynamics NAV, MS SQL Server, Wherescape RED;
 PRINCE2 Practitioner - License GR657010572SG
 GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-031
- 
            Hi @AitorEG ,
 Have you already tried to use next articles to create CDATA?
 https://stackoverflow.com/questions/4679543/how-to-write-cdata-in-xml
 https://msdn.microsoft.com/en-us/library/system.xml.xmldocument.createcdatasection.aspx
 Let's go!0
- 
            sorry, my bad. <![CDATA[]]> is valid XML. It just cannot be added as a regular node.
 check this:
 https://msdn.microsoft.com/en-us/library/system.xml.xmldocument.createcdatasection(v=vs.110).aspxSlawek Guzek
 Dynamics NAV, MS SQL Server, Wherescape RED;
 PRINCE2 Practitioner - License GR657010572SG
 GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-036
- 
            Thanks for your help.
 I am doing this noe:lvl2XMlNode := XMLDocOut.createNode(1,'collectionDateTime',''); ConsigmentXMlNode.appendChild(lvl2XMlNode); cdata := '<![CDATA[2017-12-14T11:35:00]]>'; newCDATA := lvl2XMlNode.ownerDocument.createCDATASection(cdata); //DomTextNode := XMLDocOut.createTextNode('<![CDATA[2017-12-14T11:35:00]]>'); lvl2XMlNode.appendChild(DomTextNode);
 And I receive this error: 
 "Error in the call to System.__ComObject.CreateCDataSection with the message: No valid data por a node of type 'CDATA'"
 I've used the approach found in
 https://forum.mibuso.com/discussion/comment/310306#Comment_310306
 0
- 
            Thanks, now It's working,
 I'm creating the node this way:lvl2XMlNode := XMLDocOut.createNode(1,'collectionDateTime',''); ConsigmentXMlNode.appendChild(lvl2XMlNode); cdata := '2017-12-14T11:35:00'; newCDATA := lvl2XMlNode.ownerDocument.createCDATASection(cdata); lvl2XMlNode.appendChild(newCDATA); 
 The service is still returning me an error, but al least, this step is solved.
 Thank you very much to both of you!1
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
- 323 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

