[英]How to convert xml file which is in non UTF-8 format to xml that is UTF-8 compliant
I have a huge xml file whose sample data is as follows:我有一个巨大的 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>
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:正如可以看到的那样,有文本“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.
So the query is how to take care of this in Linux environment to convert the xml file to UTF-8 compliant format?所以查询是如何在 Linux 环境中处理这个问题,将 xml 文件转换为 UTF-8 兼容格式? 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?
或者在 bash 中是否有一种方法,这样在首先创建 xml 时,我可以确保所有变量/字符串都以 UTF-8 兼容格式存储?
Use the character set conversion tool:使用字符集转换工具:
iconv -f ISO-8859-1 -t UTF-8 filename.txt
...and in file http://standards.ieee.org/develop/regauth/oui/oui.txt "aglia" (as in your example above) is reported as: ...并且在文件http://standards.ieee.org/develop/regauth/oui/oui.txt “aglia”(如您上面的示例中)报告为:
00-0B-91 (hex) Aglaia Gesellschaft für Bildverarbeitung und Kommunikation m
000B91 (base 16) Aglaia Gesellschaft für Bildverarbeitung und Kommunikation m
Tiniusstr. 12-15
Berlin D-13089
GERMANY
it seems like "ü" is the character that gets mangeld.似乎“ü”是被破坏的角色。
Update更新
When downloading "oui.txt" using wget, I see the character "ü" in the file.使用 wget 下载“oui.txt”时,我在文件中看到字符“ü”。 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
insteadcurl -o oui.txt
If 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.在这种情况下,请在下面的脚本中注释
wget
行。
I had success with the following script (update BEGIN & END to get a valid XML-file)我使用以下脚本取得了成功(更新 BEGIN & END 以获取有效的 XML 文件)
#!/bin/bash
wget http://standards.ieee.org/develop/regauth/oui/oui.txt
iconv -f iso-8859-15 -t utf-8 oui.txt > converted
awk 'BEGIN {
print "HTML-header"
}
/base 16/ {
printf("<vendor name=\"%s\">\n", $4)
read
desc = substr($0, index($0, $4))
printf("<vendorOUI oui=\"%s\" description=\"%s\"/>\n", $1, desc)
}
END {
print "HTML-footer"
}
' converted
Hope this helps!希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.