Options

Escaping characters in XML for a SOAP request

AitorEGAitorEG 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:
<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:

lbnysb8xs7fm.png

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>&lt;![CDATA[2017-12-14T11:35:00]]&gt;</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!

Best Answers

Answers

  • Options
    Slawek_GuzekSlawek_Guzek Member Posts: 1,690
    You cannot have < or > inside the node value, that's why it has been escaped

    This:
    32a7mjfztoxu.png
    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-03
  • Options
    AitorEGAitorEG Member Posts: 342
    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:

    c9mvy3m0son7.png

    "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

  • Options
    AitorEGAitorEG Member Posts: 342
    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!
Sign In or Register to comment.