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

Announcements

No record found.

News and Announcements icon
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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans