Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Is it Possible to Remove XML Declarations using XSLT?

(1) ShareShare
ReportReport
Posted on by 62

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

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,848 Most Valuable Professional on at
    Is it Possible to Remove XML Declarations using XSLT?
    Your files are not XML files. They're text files with contents resembling XML, but it's not valid XML. Therefore your question should be whether you can use XSLT to transform non-XML files. And the answer is no - XSLT is designed to transform XML files, not other files.
     
    If you really can convince the producer of these files to give you XML, I suggest you use a normal text replacement to delete all instances of <?xml version="1.0" encoding="UTF-8"?>.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans