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)

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
    237,801 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
    237,801 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

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