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)

Axapta, namespaces in XML node

(0) ShareShare
ReportReport
Posted on by 25

Hi

I'm writing Sales Invoice to XML document in Axapta 4.0

I want to add namespaces 'cbc' and 'cac' to the elements where appropiate.

(cac = CommonAggregateComponents, cbc = CommonBasicComponents)

I have tried warius forms of "element = xmlDoc.createElement('cbc' + 'UBLVersionID');"

The problem is that when I call 'xmlDoc.save(somepath);' to write the XML file, the 'cbc:' part is ignored.

Here is a job showing my methods

static void Job350(Args _args)
{
    XMLDocument                     xmlDoc;
    XMLProcessingInstruction        XMLpi;
    XMLElement                      root;
    XMLElement                      element;

    xmlDoc = new XMLDocument();

    root = xmlDoc.documentElement();

    XMLpi = xmlDoc.createProcessingInstruction('xml', 'version=\"1.0\" encoding=\"ISO-8859-1\"');
    xmlDoc.appendChild(XMLpi);

    element = xmlDoc.createElement('Invoice');
    element.setAttribute('xmlns', "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
    element.setAttribute('xmlnscac', "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateCoomponents-2");
    element.setAttribute('xmlnscbc', "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
    element.setAttribute('xmlnsccts', "urn:un:unece:uncefact:documentation:2");
    element.setAttribute('xmlnsext', "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
    element.setAttribute('xmlnsqdt', "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
    element.setAttribute('xmlnsudt', "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2");
    element.setAttribute('xmlnsxsd', "http://www.w3.org/2001/XMLSchema");
    element.setAttribute('xmlnsxsi', "http://www.w3.org/2001/XMLSchema-instance");
    element.setAttribute('xsischemaLocation', "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
    root    = xmlDoc.appendChild(element);

    element = xmlDoc.createElement('cbc:' + 'UBLVersionID');
    element.text('2.0');
    root.appendChild(element);

    xmlDoc.save("C:\\Tmp\\Out.xml");

}

 

What I would like to get should look something like this

<?xml version="1.0" encoding="ISO-8859-1"?>
<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlnscac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateCoomponents-2" xmlnscbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlnsccts="urn:un:unece:uncefact:documentation:2" xmlnsext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlnsqdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlnsudt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlnsxsd="http://www.w3.org/2001/XMLSchema" xmlnsxsi="http://www.w3.org/2001/XMLSchema-instance" xsischemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
  <cbc:UBLVersionID>2.0</cbc:UBLVersionID>
</Invoice>

but the 'cbc:' part is skipped when I run the above code.

 

Does anyone have any ideas how to solve this??

I welkome any input.

Best regards,

Brynjar

*This post is locked for comments

I have the same question (0)
  • Alex Prodan Profile Picture
    on at

    Hi,

     Have you looked at XmlDoc.createElement2 and createElement3 methods? I have replaced this

    [quote user="Brynjar Gudbjartsson"] element = xmlDoc.createElement('cbc:' + 'UBLVersionID');
    [/quote] 

    with this line:

    element = xmlDoc.createElement3('cbc', 'UBLVersionID', 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2');

    and got this:

    <cbc:UBLVersionID xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">2.0</cbc:UBLVersionID>

    By the way, aren't you suppose to have : between xmlns and the namespace prefix? 'xmlns:cbc', not 'xmlnscbc'...

  • Brynjar Gudbjartsson Profile Picture
    25 on at

    Hi

     Thanks for your input.

    You are right about the : (colon) it is suposed to xmlns:cbc

    And also if I use createElement3 then it works.

    So the code

        element = xmlDoc.createElement('Invoice');
        element.setAttribute('xmlns', "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
        element.setAttribute('xmlns:cac', "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateCoomponents-2");
        element.setAttribute('xmlns:cbc', "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
        element.setAttribute('xmlns:ccts', "urn:un:unece:uncefact:documentation:2");
        element.setAttribute('xmlns:ext', "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
        element.setAttribute('xmlns:qdt', "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
        element.setAttribute('xmlns:udt', "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2");
        element.setAttribute('xmlns:xsd', "http://www.w3.org/2001/XMLSchema");
        element.setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
        element.setAttribute('xsi:schemaLocation', "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2");
        root    = xmlDoc.appendChild(element);

        element = xmlDoc.createElement3('cbc', 'UBLVersionID', "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
        element.text('2.0');
        root.appendChild(element);

    does the trick.

    Thanks again

    Brynjar 

     

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans