XML Declaration - writing encoding in lowercase
Hi!
I have a problem getting the new xmlDocument to work for export in 2018 CU5 SE.
Creating and adding the declaration in my XMLDocument.

...
Exporting it to a file.

The result:

Double click it, the file is "corrupt". Tried to upload it to the service and got the same error. (sorry about the Swedish, it says can't show the xml! :-) )

Manually changed it to UPPERCASE

It works fine!
Why? Am I doing anything wrong or is the xmlfunction converting my encoding text to lowercase? This doesn't seem to work with anything. I did try to change it to UTF-8 and exporting it. Same result.
Any news or comments on this?
Hi @NSilvergrund, Apologies for a late response.
The encoding value is lowercased automatically in the internals of .NET, e.g.:
Encoding.GetEncoding("ISO-8859-1").BodyName
"iso-8859-1"
I think that according to the standards, encoding value should be treated as case insensitive. Perhaps this is just the problem in the tools that you are using? Was that a screenshot from the browser?
Hi Dennis.
I'm creating an export to the Swedish Tax Agency, and it will not take lowercase. I'm getting an error when uploading it. I'm not an xml expert though, but if the "encoding value should be treadted as case insensitive", why are you lowering it then? It did work in a NAV2017.
The screenshot was from a browser, don't know if it was edge, ie or chrome, same error either way.
We don't lowercase on purpose. This happens only because we use an Encoding class from .NET framework, which apparently stores encoding name in the lowercased format. In Nav 2017 you most likely used .NET functionality directly (XmlDocument or XDocument) and were saving XML without the use of the Encoding class.
Nevertheless, we should indeed preserve the formatting supplied by the developer.
In 2017 I've been using:
RequestBodyXmlDoc@1003 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument"; DocType@1100583013 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocumentType";
And in 2018 I use:
xmlDoc: XmlDocument; xmlDec: XmlDeclaration; xmlDocType: XmlDocumentType;
The reason why I have to do it with .NET is that I'm forced to have the DocumentType in the xml file, and can't find a way in a xmlport to provide that. I assumed that you're using the "same" dll's in the background.
What is your suggested solution? As it is I can't use the file exported from NAV2018, because of the lowercasing.
The new AL types use .NET's XDocument in the background (not XmlDocument). When XDocument is saved into a string, it does not print its declaration, so the encoding has to be explicitly set on the TextWriter. And this where the .NET's Encoding class comes into play and lowercases the encoding name.
Until this is fixed, I think the only solution is to make a text replace in AL - save XmlDocument to a text variable, replace encoding value, then save text variable to the out stream.