gpt4 book ai didi

parsing - xmllint - 使用命名空间解析 xml 文件

转载 作者:行者123 更新时间:2023-12-04 16:54:56 25 4
gpt4 key购买 nike

我在 stackoverflow 上找到了很多关于 xmllint 及其“命名空间支持”的主题,但没有一个对我有帮助。

这是我的 xml(准确地说是 xsd)文件:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema">
<xsd:annotation>
<xsd:documentation>My Text</xsd:documentation>
</xsd:annotation>
</xsd:schema>

我想从这个文件中检索“我的文本”链,所以我试试这个:
xmllint myfile.xsd --xpath "/*[namespace-uri()='http://www.w3.org/2001/XMLSchema' and 
name()='schema']/*[namespace-uri()='http://www.w3.org/2001/XMLSchema' and
name()='annotation']/*[namespace-uri()='http://www.w3.org/2001/XMLSchema' and
name()='documentation']/text()"

但它不起作用。我收到“段错误”。

更新

我有另一个问题:
我应该使用什么来在此文件中获取我的标签属性“toto”值:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:toto="testAtributeValue">
<xsd:annotation>
<xsd:documentation>myText</xsd:documentation>
</xsd:annotation>
</xsd:schema>

换句话说,我想得到“testAtributeValue”

最佳答案

您的 XML 无效,因为未声明“xsd”前缀(甚至在问题的第二个 .version 中编辑的命令输出中也报告了这一点)。

你要xmlns:xsd=不是 xmlns= .

还有 name()返回一个 QName。您要使用 local-name()匹配本地名称。

关于parsing - xmllint - 使用命名空间解析 xml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19425559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com