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)

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

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,152 Most Valuable Professional on at

    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.

  • Community Member Profile Picture
    on at

    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">

  • Verified answer
    Martin Dráb Profile Picture
    239,152 Most Valuable Professional on at

    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());
  • Community Member Profile Picture
    on at

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

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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 16

#2
GiacomoRovai Profile Picture

GiacomoRovai 4

#3
Douglas Noel Profile Picture

Douglas Noel 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans