Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to include a double quote in XML using .setattribute?

(0) ShareShare
ReportReport
Posted on by

I'm trying to use the setattribute function to create a "noNamespaceschemalocation" attribute in an XML document but can't figure out the syntax for a get a double quote rather than it being converted to '&quote;', below is the code I am using; does anyone one what I should be doing?

{

XmlDocument xmlDoc;

XmlElement  xmlTransaction;

;

xmlDoc = XmlDocument::newBlank();
xmlTransaction = xmlDoc.createElement('transaction');
xmlTransaction.setAttribute('xmlns:xsi', 'www.w3.org/.../XMLSchema-instance" xsi:noNamespaceSchemaLocation="import_spec.xsd');

The following is created from the above code:


<transaction xmlns:xsi="www.w3.org/.../XMLSchema-instance&amp;quot; xsi:noNamespaceSchemaLocation=&quot;import_spec.xsd">

I want to create the following:


<transaction xmlns:xsi="www.w3.org/.../XMLSchema-instance" xsi:noNamespaceSchemaLocation="import_spec.xsd">

*This post is locked for comments

  • RE: How to include a double quote in XML using .setattribute?

    Thanks Martin, that was exactly what I needed. I appreciate the help.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: How to include a double quote in XML using .setattribute?

    The problem is that the second argument of setAttribute2() has a wrong value. It should be the namespace URI and when you use 'xsi', the application considers it as a new namespace with URI = xsi, adds a declaration for it (xmlns:p2="xsi") and uses this new namespace for your attribute.
    The right code is this:

    XmlDocument xmlDoc = XmlDocument::newBlank();
    XmlElement xmlTransaction = xmlDoc.createElement('transaction');
    xmlDoc.appendChild(xmlTransaction);
    
    xmlTransaction.setAttribute('xmlns:xsi', 'www.w3.org/.../XMLSchema-instance');
    xmlTransaction.setAttribute2('noNamespaceSchemaLocation', 'www.w3.org/.../XMLSchema-instance', 'import_spec.xsd');
    
    info(xmlDoc.xml());
  • RE: How to include a double quote in XML using .setattribute?

    Thanks for the response Martin. I have tried pretty much every response doing a Google search and have tried what you suggested and it does come close, see below.

    My code:

    xmlDoc = XmlDocument::newBlank();

    xmlTransaction = xmlDoc.createElement('transaction');

    xmlTransaction.setAttribute('xmlns:xsi', 'www.w3.org/.../XMLSchema-instance&;);

    xmlTransaction.setAttribute2('noNamespaceSchemaLocation', 'xsi',  'import_spec.xsd');

    The result:

    <transaction xmlns:xsi="www.w3.org/.../XMLSchema-instance&quot; p2:noNamespaceSchemaLocation="import_spec.xsd" xmlns:p2="xsi">

    I need:

    <transaction xmlns:xsi="www.w3.org/.../XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation="import_spec.xsd">

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: How to include a double quote in XML using .setattribute?

    You call setAttribute() only once, although you're trying to add two attributes (xsi and noNamespaceSchemaLocation), which is clearly a problem.

    For the latter attribute, use setAttribute2(). Its third argument is value, where you should set import_spec.xsd.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans