5

我想将 UTF-8 数字引用转换为 xmllint 输出中的字符。

重现:

$ wget http://il.srgssr.ch/integrationlayer/1.0/ue/rts/video/play/4727630.xml
$ xmllint --xpath "/Video/AssetMetadatas/AssetMetadata/title/text()" 4727630.xml && echo
Le jardin apprivoisé - Entre pierre et bois

我希望输出是:

Le jardin apprivoisé - Entre pierre et bois

我已经阅读了手册页并尝试了不同的选项,但没有任何效果。

如果可能的话,我想使用 xmllint 中的选项来实现这一点,或者如果使用 Linux 发行版中常见的另一个命令行工具无法做到这一点。

谢谢!

4

3 回答 3

5

我知道这个问题有点过时了,因为我从谷歌来到这里并希望为未来的访问者分享可能的答案。有必要稍微改变 xpath 表达式并使用 string() 函数而不是 text():

$ wget http://il.srgssr.ch/integrationlayer/1.0/ue/rts/video/play/4727630.xml
$ xmllint --xpath "string(/Video/AssetMetadatas/AssetMetadata/title)" 4727630.xml
Le jardin apprivoisé - Entre pierre et bois
于 2016-09-09T10:20:10.547 回答
0

我找到了另一种我认为可以完全解决这个问题的方法。诀窍是使用recodeGNU 提供的库将输出编码从 更改htmlutf8.

$ wget http://il.srgssr.ch/integrationlayer/1.0/ue/rts/video/play/4727630.xml
$ xmllint --xpath "/Video/AssetMetadatas/AssetMetadata/title/text()" 4727630.xml | 重新编码 html..utf8
Le jardin apprivoisé - Entre pierre et bois

recode可以使用apt-get install recode.

于 2020-11-09T15:10:59.293 回答
-2

旧的 sed 和 echo 怎么样?

$ wget http://il.srgssr.ch/integrationlayer/1.0/ue/rts/video/play/4727630.xml
$ echo -e $(xmllint --xpath "/Video/AssetMetadatas/AssetMetadata/title/text()" 4727630.xml | sed -e 's/&#x/\\u/g' -e 's/;//g')
Le jardin apprivoisé - Entre pierre et bois
于 2021-09-07T04:05:53.657 回答