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

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
    25,157 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
    25,157 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

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