Skip to main content
Post a question

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id : uvAkCtmOtNCtxKnZfo1pFH
Finance | Project Operations, Human Resources, ...
Answered

Is it Possible to Remove XML Declarations using XSLT?

Like (1) ShareShare
ReportReport
Posted on 1 Apr 2024 08:25:32 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
    231,723 Most Valuable Professional on 01 Apr 2024 at 10:04:13
    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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,850 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans
Loading complete