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

AL XML Generation - Namespace prefixes not being applied correctly

(3) ShareShare
ReportReport
Posted on by 79
I'm working with Business Central AL and trying to generate a SOAP XML request with specific namespace prefixes, but some elements aren't getting the prefixes applied correctly.
 
Problem
When generating XML, elements like Header, Body, and CustomerAccounts should have namespace prefixes (soapenv: and psp:), but they're either getting default namespaces or no prefixes at all.

 
Current Output
<Envelope
	xmlns:soapenv="http://hidden.com/"
	xmlns:abc="http://hidden.com"
	xmlns:123="http://hidden.com" xmlns="soapenv">
	<Header/ xmlns="soapenv">
	<Body xmlns="soapenv">
		<CustomerAccounts xmlns="abc">
			...
		</CustomerAccounts>
	</Body>
</Envelope>
Desired Output
<soapenv:Envelope
	xmlns:soapenv="http://hidden.com/"
	xmlns:abc="http://hidden.com"
	xmlns:123="http://hidden.com">
	<soapenv:Header/>
	<soapenv:Body>
		<abc:CustomerAccounts>
			...
		</abc:CustomerAccounts>
	</soapenv:Body>
</soapenv:Envelope>
AL Code
local procedure CreateBaseXML(
        namespacePrefix: Text;
        namespaceURI: Text
    ): XmlDocument
    var
        XMLDoc: XmlDocument;
        XMLDec: XmlDeclaration;
        XMLElem: XmlElement;
        XMLElem2: XmlElement;
        XMLAtr: XmlAttribute;
    begin
        XMLDoc := XmlDocument.Create();
        XMLDec := XmlDeclaration.Create('1.0', 'UTF-8', 'yes');
        XMLDoc.SetDeclaration(XMLDec);

        XMLElem := XmlElement.Create('Envelope', namespacePrefix);
        XMLAtr := XmlAttribute.CreateNamespaceDeclaration('123', 'http://hidden.com/');
        XMLElem.Add(XMLAtr);
        XMLAtr := XmlAttribute.CreateNamespaceDeclaration('abc', 'http://hidden.com/');
        XMLElem.Add(XMLAtr);
        XMLAtr := XmlAttribute.CreateNamespaceDeclaration(namespacePrefix, namespaceURI);
        XMLElem.Add(XMLAtr);

        XmlElem2 := XmlElement.Create('Header', namespacePrefix);
        XMLElem.Add(XmlElem2);

        XMLElem2 := XmlElement.Create('Body', namespacePrefix);
        XMLElem.Add(XMLElem2);

        XMLDoc.Add(XMLElem);
        exit(XMLDoc);
    end;
Assume namespacePrefix and namespaceURI is set accordingly i.e., CreateBaseXML('soapenv', 'https://soapenv.com');
 
What I've Tried
  1. Using XmlElement.Create('prefix:ElementName') syntax
  2. Adding namespace declarations with CreateNamespaceDeclaration
  3. Different combinations of namespace parameters in element creation
How can I ensure the namespace prefixes are applied correctly to all appropriate elements in AL-generated XML?
 
 
I have the same question (0)
  • Verified answer
    DK-27050928-0 Profile Picture
    79 on at
    I created the Xml elements and passed in the Prefix rather than the Uri i.e.,

    It was:
    XmlElem2 := XmlElement.Create('Header', namespacePrefix);
     
    Rather than:
    XmlElem2 := XmlElement.Create('Header', namespaceUri);
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    22,292 Super User 2026 Season 1 on at

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,831 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,122 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 690 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans