Hello D365fo Community,
I'm currently facing a challenge with XML transformations within Dynamics 365 for Finance and Operations. Specifically, I'm dealing with XML files that contain multiple XML declarations (<?xml version=/1.0/ encoding=/UTF-8/?>
) throughout the document, rather than just at the beginning.
For example:
<?xml version=/1.0/ encoding=/UTF-8/?>
<MESSAGE>
<ENTETE>
<NUM>40156939</NUM>
</ENTETE>
</MESSAGE>
<?xml version=/1.0/ encoding=/UTF-8/?>
<MESSAGE>
<ENTETE>
<NUM>40156940</NUM>
</ENTETE>
</MESSAGE>
I'm aware that XML declarations should appear only once at the beginning of an XML document. However, due to the nature of these files, they contain multiple declarations interspersed with XML content.
My question to the community is: Is it possible to remove these extra XML declarations using XSLT?
I've explored various approaches, but I'm unsure if XSLT alone can handle this scenario efficiently. If anyone has experience or insights into this matter, I would greatly appreciate your guidance.
Also, I'm getting this Error each time I try to run the XSLT on the File (I use Chocolatey command {xsltproc trans.xslt myfile.dat > res.xml} with powerShell)
myfile.dat:6: parser error: XML declaration allowed only at the start of the document.
<?xml version=/1.0/ encoding=/UTF-8/?>
^
myfile.dat:7: parser error: Extra content at the end of the document
Thank you in advance for your assistance!
Best regards,
Hatem
André Arnaud de Cal...
291,979
Super User 2025 Season 1
Martin Dráb
230,848
Most Valuable Professional
nmaenpaa
101,156