代码之家  ›  专栏  ›  技术社区  ›  Aleksandar

xmllint仅选择第一个元素

  •  1
  • Aleksandar  · 技术社区  · 7 年前

    我想提取每个 <id> 具有的元素 xmllint 输入文本文件。

    <rss>
        <channel>
            <item>
                <id>111</id>
                <description>text 1</description>
            </item>
            <item>
                <id>222</id>
                <description>text 2</description>
            </item>
            <item>
                <id>333</id>
                <description>text 3</description>
            </item>
        </channel>
    </rss>
    

    每个元素应位于文本文件中的单独一行,如下所示:

    111
    222
    333
    

    我已经无法选择所有元素了。出于某种原因,我的 xmllint 命令仅返回第一个元素。

    xmllint test.xml --xpath "string(//id)"
    

    我试过很多不同的方法 --xpath 声明,但似乎无法理解。

    (我不知道是否相关,但我正在使用 xmllint 在OS X上)

    1 回复  |  直到 7 年前
        1
  •  0
  •   Aleksandar    7 年前

    xmllint—外壳测试。xml<<&书信电报; echo 'cat //id/text()' &燃气轮机;出来txt文件