问题标签 [xmllint]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
xml - XPath 脚本不适用于输入 1,但适用于输入 2
好的,我不确定如何描述我的问题,基本上我有一个 XML 文件,我试图通过在 XML 文件中搜索包含字符串的节点来获取一些信息。
我的问题是,如果我只包含<table>
我感兴趣的标签而不是整个 XML 文件,那么下面的脚本就可以完成这项工作。那就是我所说的输入二,效果很好。
但如果我使用整个 XML 文件,它就不起作用,这是脚本:
(tidy -asxml input.xml | xmllint --xpath 'descendant-or-self::*[starts-with(text(), "Aktiv tid:")]/following-sibling::*/text()' -) 2>/dev/null
这是输入的一个 XML 文件(完整的 XML 文件):
这是输入的两个 XML 文件:
因此,由于某种原因,如果我删除之前并包括这一行的所有内容:
<div class='contentcontainer'>
该脚本工作正常。
这对我来说似乎很奇怪,但似乎是一个非常基本的问题。
所以我的问题是我该如何解决这个问题?
提前致谢!
linux - 使用 xmllint 格式化 apache2 虚拟主机 conf
我想智能缩进我的 apache2 虚拟主机 conf 文件。我在这里找到了如何智能缩进 xml 文件。但虚拟主机 conf 文件不是有效的 xml 文件。
例如,如果我尝试在 apache2 存储库中给出的 000-default.conf 上使用 xmllint,我会收到一个错误:
有没有人知道如何处理这个问题?
bash - bash 脚本将 XML 数据提取为列格式
尝试从多个字符串输出中动态提取 xml 数据(数据更改)为列格式。
当我对 SQL 数据库运行查询时,其中大约 100 个 XML 位会回显。
我需要的是列格式的 and 。本质上,在主机名等于主机名-H-A10D 的情况下,我希望能够匹配最后的 D 并将第一列标记为 Dev,Q 作为测试,最后没有字母作为 Prod。所以输出看起来像 -->
我玩过 sed/awk/etc ,而不仅仅是在不写出临时平面文件的情况下无法获得我想要的格式。我更喜欢使用 xmlstarlet 或 xmllint 之类的东西将它放入一个数组中。当然可以提出更好的建议,这就是我在这里的原因:) 谢谢大家。
xml - 带有 XPATH 的 Linux Bash XMLLINT
今天我开始学习如何正确使用 xmllint。它似乎没有得到很好的覆盖或解释。我计划使用单一语言资源文件来运行我的整个系统。我混合了必须从此语言文件读取的 bash 脚本和 php 页面。
目前我在我的 xml 文件 en.xml 中使用以下格式:
现在我需要从一个 bash 脚本行开始,它应该从 xml 文件中提取数据值。例如,我想DESCRIPTION
从index.php
item 中获取 value。
我正在使用
对于有效的不同布局,但是现在我正在更改 xml 文件的布局,我不知道如何最好地定位特定的目标<item>
,然后在 bash 脚本中深入到它的子元素。
有人可以帮忙用一条xmllint --xpath
线来获得这个值吗?
xml - XML:类型定义不存在
我正在使用这个[1] XML Schema 来验证带有 xmllint 的 XML 文档:
验证失败
metadata.xml 中的第 55 行:
但是,有一个我想要的示例文档。它位于此处[2]。
当我根据架构验证此示例时,会发生相同的验证错误。
我错过了什么?
xpath - 如何将 string() 函数应用于每个属性?
我需要在 Bash 脚本中获取一些超引用。
以下命令使用curl
andxmllint
读取href
HTML 页面的所有属性:
但我只需要属性的值。可以使用string()
函数选择属性的值。但是如果我使用它,我只会得到属性列表的第一个元素:
如何将string()
函数应用于每个属性?
xml - xmllint 和 xpath 从 https://mail.google.com/mail/feed/atom 解析 xml 数据
我从我的 gmail 帐户中获取了一些我想解析的 xml 数据。xml 数据如下所示:
我希望获得所有条目的所有标题,例如:
现在,我发现如果没有这个 xmlns 信息,这将起作用。但是有了 xmlns 信息,我得到了消息
XPath 集为空
我想要一个简单的 oneliner 来解析这个文件,而不必修改文件(删除 xmlns 部分)。
--> 编辑:感谢@Mathias,正确的在线人看起来像: echo "setns x= http://purl.org/atom/ns# \nxpath /x:feed/x:entry/x:title/text( )"
xml - How to get the tag “<yweather:condition>” from Yahoo Weather RSS with xmllint
Let's try to parse and extract node from Yahoo Weather RSS.
URL is here http://weather.yahooapis.com/forecastrss?w=12602818&u=c
xmllint has to be used for this purpose.
Here is the node to extract:
The problem
A naive xmllint --xpath "//yweather:condition" the_rss_file_from_yahoo
replied with an error:
It has to comes from the fact there's a namespace defined. But we're stuck here.
Is it possible to get this node with xmllint, on the command line? And if yes, how?
Edit/Answer:
As the question was marked duplicated, if you're a XPath newbie like me looking for a one-liner solution, you may use xmllint filename --xpath "//*[local-name()='condition']"
, with two slashes contrarily to the other question, which was using one (because it was accessing the root node). However for the formal way to address this, see answer A) from the original question and use // instead of / in the XPath query (Thanks Tomalek for helping me out).