如何将非 UTF-8 格式的 xml 文件转换为符合 UTF-8 格式的 xml
我有一个巨大的 xml 文件,其示例数据如下:
<vendor name="aglaia"><br>
<vendorOUI oui="000B91" description="Aglaia Gesellschaft für Bildverarbeitung ud Kommunikation m" /><br>
</vendor><br>
<vendor name="ag"><br>
<vendorOUI oui="0024A9" description="Ag Leader Technology" /><br>
</vendor><br>
可以看到有文本“Gesellschaft für Bildverarbeitung”,它不符合 UTF-8 标准,因为我从 xml 验证器收到错误,错误如下:
Import failed: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
那么问题来了,在Linux环境下如何处理这个问题,将xml文件转换为UTF-8兼容格式呢?或者 bash 中有没有一种方法可以在首先创建 xml 时确保所有变量/字符串都以 UTF-8 兼容格式存储?
I have a huge xml file whose sample data is as follows :
<vendor name="aglaia"><br>
<vendorOUI oui="000B91" description="Aglaia Gesellschaft für Bildverarbeitung ud Kommunikation m" /><br>
</vendor><br>
<vendor name="ag"><br>
<vendorOUI oui="0024A9" description="Ag Leader Technology" /><br>
</vendor><br>
as it can be see there are text " Gesellschaft für Bildverarbeitung " which is not UTF-8 compliant because which I am getting errors from the xml validator , errors like:
Import failed: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
So the query is how to take care of this in Linux environment to convert the xml file to UTF-8 compliant format? or is there a way in bash such that while creating the xml in the first place i can ensure that all variables/strings are stored in UTF-8 compliant format?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用字符集转换工具:
请参阅 gnu-page
...并在文件 http://standards.ieee.org/develop/regauth/oui/oui.txt“aglia”(如上面的示例)报告为:
看起来“ü”是被破坏的角色。
更新
使用 wget 下载“oui.txt”时,我在文件中看到字符“ü”。如果您没有,那么您下载的内容就会损坏。考虑使用其中之一:
wget --header='Accept-Charset: utf-8'
curl -o oui.txt
如果上述方法均不起作用,只需在您喜欢的浏览器中打开链接并执行“另存为”即可。在这种情况下,请注释下面脚本中的
wget
行。我成功使用了以下脚本(更新 BEGIN 和 END 以获取有效的 XML 文件)
希望这有帮助!
Use the character set conversion tool:
See gnu-page
...and in file http://standards.ieee.org/develop/regauth/oui/oui.txt "aglia" (as in your example above) is reported as:
it seems like "ü" is the character that gets mangeld.
Update
When downloading "oui.txt" using wget, I see the character "ü" in the file. If you don't have that something is broken in your download. consider using one of these:
wget --header='Accept-Charset: utf-8'
curl -o oui.txt
insteadIf none of the above works, just open the link in you favorite browser and do a "save as". In that case, comment the
wget
line in the script below.I had success with the following script (update BEGIN & END to get a valid XML-file)
Hope this helps!