如何忽略xml中没有引号的属性 [英] how to ignore attribute without quotes in xml
本文介绍了如何忽略xml中没有引号的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想计算tag1出现了多少次给出这个 123.xml 文件(来自互联网)
i want to count how many times tag1 occurs givin this 123.xml file ( streaming from the internet)
<startend>
<tag1 name=myname>
<date>10-10-10</date>
</tag1 >
<tag1 name=yourname>
<date>11-10-10</date>
</tag1 >
</startend>
使用:xmlstarlet sel -t -v "count(//tag1)" 123.xml
输出:
AttValue: " 或 ' 预期属性构造错误
AttValue: " or ' expected attributes construct error
如何忽略属性没有"?
推荐答案
您输入的 XML/HTML 结构包含无效标签/属性,应提前恢复:
You input XML/HTML structure has invalid tags/attributes and should be recovered beforehand:
xmlstarlet
解决方法:
xmlstarlet
solution:
xmlstarlet fo -o -R -H -D 123.xml 2>/dev/null | xmlstarlet sel -t -v "count(//tag1)" -n
输出:
2
<小时>
详情:
fo(或格式)
- 格式化 XML 文档-o 或 --omit-decl
- 省略 xml 声明-R 或 --recover
- 尝试恢复可解析的内容-D 或 --dropdtd
- 删除输入文档的 DOCTYPE-H 或 --html
- 输入是 HTML2>/dev/null
- 抑制错误/警告
fo (or format)
- Format XML document(s)-o or --omit-decl
- omit xml declaration-R or --recover
- try to recover what is parsable-D or --dropdtd
- remove the DOCTYPE of the input docs-H or --html
- input is HTML2>/dev/null
- suppress errors/warnings
这篇关于如何忽略xml中没有引号的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文