web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Encode single and double quote characters in XMLDocument.createtextnode method

(0) ShareShare
ReportReport
Posted on by

I am trying to create a xml text node using

XMLDocument.createtextnode(temp);

Case 1 -> if temp = "One&two"', then the value is being encoded properly by default with escape character as &amp; as expected. I can see "&" on XML viewer, this is properly escaped with &amp; when I open the XML in edit mode. Same is the case for "<" and ">".

Case 2: if temp = "One'two" or "one"two", single quote and double quotes are not encoded to &apos;  and &quot; as expected.

When I try to encode explicitly and pass the value to XMLDocument.createtextnode(System.Security.SecurityElement::Escape(temp)) 

String One'Two is encoded as One&amp;apos;Two. Is there a way to encode One'Two to One&apos;Two and

One"Two to One&quot;Two?

Thanks,

Praveen

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    jasman Profile Picture
    1,413 on at

    Why not use:
        XmlDocument xmlDoc;
        XmlElement xmlRoot;
        XmlElement xmlField;

        xmlDoc = XmlDocument::newBlank();
        xmlRoot = xmlDoc.createElement("Root");
        xmlField = xmlRoot.createElement("one&two");
        xmlField.innerText(value);
        xmlRoot.appendChild(xmlField);

    Seems to me that this handles the encoding just fine.

  • Community Member Profile Picture
    on at

    Yes you are right. It works for '&' , '<', '>' but not for single and double quotes. Parsed xml is like below as expected:

    <?xml version="1.0" encoding="utf-8"?>
    <Root>
      <one>Te&amp;st</one>
    </Root>

    if the xml value has a single or double quotes for eg: Te'st parsed xml looks like <one>Te'st</one> . Is there a way to have parsed xml as <one>Te&apos;st</one>

  • Sagar Dedhia Profile Picture
    50 on at

    Did anyone found answer ? I am having same problem while exporting to XML

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans