How can I remove these hidden characters that are at the beginning of the file (before Allitems
)? When I open the file regularly, they can't be seen of course. Used an online tool that detected them.
How can I prevent them from appearing in the first place (using some SaaS that generates XMLs)?
XML document:
1 <Allitems>
2
3 <Item>
4 <PostTitle>Must Have 1000 Hacking Tut</PostTitle>
5 <UserName>Mr.HacKer</UserName>
6 <ForumName>Advanced Hacking Tutorials</ForumName>
7 <PostLink>http://offensivecommunity.net/showthread.php?tid=676</PostLink>
8 <PostContent>HEllo IHF Guys
That's a Byte Order Mark (BOM), an optional 4-byte indicator of the endianness (byte order) of the file. You cannot prevent a BOM from occurring in the first place if you don't control the source of the file, but you can remove it...
You can follow the instructions offered by the W3C for the removal the BOM from HTML pages, which apply to XML as well. Various other Stack Overflow answers also offer ways to remove a BOM:
# vim file.xml
:set nobomb
:wq
Using a standalone Windows freeware program, File BOM Detector.