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 :
Finance | Project Operations, Human Resources, ...
Answered

Is it Possible to Remove XML Declarations using XSLT?

(1) ShareShare
ReportReport
Posted on by 66

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

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at
    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

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans