Remove hidden characters from XML

眉间皱痕 提交于 2019-12-08 07:33:50

问题


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

回答1:


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...

BOM Removal

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:

  • Using VIM:

    # vim file.xml
    :set nobomb
    :wq
    
  • Using a standalone Windows freeware program, File BOM Detector.

  • Using a freeware Windows editor, Notepad++: Under the Format menu, select Encode in UTF-8 without BOM.


来源:https://stackoverflow.com/questions/32114841/remove-hidden-characters-from-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!