Skip to main content
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.
  • Suggested answer
    GL-04040221-0 Profile Picture
    2 on at
    xml attribute prefix
    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 :)
  • Gerardo Rentería García Profile Picture
    20,949 Most Valuable Professional on at
    xml attribute prefix
    Hi
    I haven't come across this topic, I found this. I keep searching and I share with you.
    Best Regards
    Gerardo 
  • Magicrevette Profile Picture
    215 on at
    xml attribute prefix
    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
  • Suggested answer
    Gerardo Rentería García Profile Picture
    20,949 Most Valuable Professional 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

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans