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...
Suggested Answer

xml attribute prefix

(0) ShareShare
ReportReport
Posted on by 215
Hello,
 
I want to create in AL an xml document with a custom prefix attribute in the root tag, like this :
 
<root xsi:schemaLocation=/http://myschemaurl/>
...
</root>
 
How can I do that in a codeunit in AL ? I tried different methods on XmlElement variables, but couldn't have the above result.
 
Thank you.
I have the same question (0)
  • Suggested answer
    Gerardo Rentería García Profile Picture
    26,102 Most Valuable Professional on at
  • Magicrevette Profile Picture
    215 on at
    I'm not using xmlport to create my xml. I'm using a codeunit, with XmlDocument.Create and XmlElement.Create() methods. SO I can't use namespace prefix property in this case.
     
    With what you suggested me, I could have done something like this :
     
    <root XMLNS:prefix=/http://myschemaurl/>
    ...
    </root>
     
    But what I want is to set an attribute in my root tag something different from xmlns, like this :
     
    <root XSI:prefix=/http://myschemaurl/>
    ...
    </root>
     
    Since the attribute name is not 'XMLNS', it is not a namespace anymore, just an attribute.
     
    Any idea how i can do that in AL ?
     
    Thank you
  • Gerardo Rentería García Profile Picture
    26,102 Most Valuable Professional on at
    Hi
    I haven't come across this topic, I found this. I keep searching and I share with you.
    Best Regards
    Gerardo 
  • Suggested answer
    GL-04040221-0 Profile Picture
    2 on at
    Hi,
     
    I have spent a lot of time investigating the same issue lately.  The nearest I found was to use the XMLAttribute variable with 3 parameters (XmlAttribute.Create(Text, Text, Text) Method - Business Central | Microsoft Learn), but this also does not work, as it returns a default prefix value (p1, p2 etc) and ignores any attempt to override the prefix value from my end.
     
    I ran out of time in the end, and decided to solve this the old fashioned way by creating my root as text first then adding it to the XMLDocument:
     
    local procedure CreateXMLRoot(var XMLDoc: XmlDocument)
        var
            XmlText: Text;
     
        begin
            XmlText := '<melding xmlns="urn:***********:v1" '
            + 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
            + 'xsi:schemaLocation="urn:***********:v1 ***********_v1_0.xsd ">'
            + '</melding>';
            XmlDocument.ReadFrom(XmlText, XMLDoc);
        end;
    Don't know if this will help you, but it seems to work so far in my testing. 
    It's almost ridiculous to have to spend so much time on such an old fashioned file format, but people are still using xml, so we must perservere :)

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,853 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 915 Super User 2026 Season 1

#3
Teagen Boll Profile Picture

Teagen Boll 643 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans