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 :
Small and medium business | Business Central, N...
Suggested Answer

How to add namespace prefix with xml node name like <h: table>

(0) ShareShare
ReportReport
Posted on by 241

Hi, 

Hope you all are doing well. 

I'm trying to build following xml in AL

<?xml version="1.0" encoding="UTF-8" standalone=""?>

<Invoice
    xmlns:cac="is:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
    xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
    xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
    <ext:UBLExtensions>
        <ext:UBLExtension>urn:oas
            <ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI>
        </ext:UBLExtension>
    </ext:UBLExtensions>
</Invoice>
I wrote following piece of code to get the xml given above.

local procedure BuildXml(): Text
    var
        XmlDoc: XmlDocument;
        XmlDec: XmlDeclaration;
        InvoiceElement: XmlElement;
        UBLExtensionsElement: XmlElement;
        UBLExtensionElement: XmlElement;
        ExtensionURIElement: XmlElement;
        NameSpaceUrl: Text;
        XmlIntoText: Text;
    begin
        XmlDoc := XmlDocument.Create();
        XmlDec := XmlDeclaration.Create('1.0', 'UTF-8', '');
        XmlDoc.SetDeclaration(XmlDec);
        NameSpaceUrl := 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2';
        InvoiceElement := XmlElement.Create('Invoice', NameSpaceUrl)
        InvoiceElement.Add(XmlAttribute.CreateNamespaceDeclaration('cac', 'is:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'));
        InvoiceElement.Add(XmlAttribute.CreateNamespaceDeclaration('cbc', 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2'));
        InvoiceElement.Add(XmlAttribute.CreateNamespaceDeclaration('ext', 'urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2'));

        UBLExtensionsElement := XmlElement.Create('UBLExtensions', NameSpaceUrl)
        UBLExtensionElement := XmlElement.Create('UBLExtension', NameSpaceUrl, 'urn:oas');
        ExtensionURIElement := XmlElement.Create('ExtensionURI', NameSpaceUrl);
        ExtensionURIElement.Add(XmlText.Create('urn:oasis:names:specification:ubl:dsig:enveloped:xades'));

        UBLExtensionElement.Add(ExtensionURIElement);
        UBLExtensionsElement.Add(UBLExtensionElement);
        InvoiceElement.Add(UBLExtensionsElement);

        XmlDoc.Add(InvoiceElement);
        XmlDoc.WriteTo(XmlIntoText);
        exit(XmlIntoText);
    end
By running the code given above, I'm getting the following xml output.
<?xml version="1.0" encoding="UTF-8" standalone=""?>
<Invoice
    xmlns:cac="is:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
    xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
    xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
    xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
    <UBLExtensions>
        <UBLExtension>urn:oas
            <ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ExtensionURI>
        </UBLExtension>
    </UBLExtensions>
</Invoice>
As we can see, the prefix 'ext' is missing with each child node. Can anyone please tell me how can I add the ext prefix with an XmlNode's or XmlElement's Name?
Answers will be highly appreciated.
I have the same question (0)
  • Suggested answer
    Marco Mels Profile Picture
    on at

    Hello,

    We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist. If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    www.dynamicsuser.net/.../14

    I will open this up to the community in case they have something to add.

    Thanks.

  • Ameer Hamza Profile Picture
    5 on at

    Hi can you find any solution

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,229

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,867 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans