【问题标题】:Finding nested tag values of XML file using Shell Script使用 Shell 脚本查找 XML 文件的嵌套标记值
【发布时间】:2020-04-13 03:59:53
【问题描述】:

我有一个 XML 文件的格式:

<classes>

 <subjects>
    <subject>
        <name>Operating System</name>
        <credit>3</credit>
        <type>Theory + Lab</type>
        <faculty>Prof. XYZ</faculty> 
    </subject>

    <subject>
        <name>Web Development</name>
        <credit>3</credit>
        <type>Theory + Lab</type>
        <faculty>Prof. ABC</faculty> 
    </subject>
 </subjects>

</classes>

我需要找到嵌套在 /subject/subjects 标签内的“name”标签的值。 如何获取“name”标签的值?

【问题讨论】:

    标签: xml shell


    【解决方案1】:

    Shell 解释器(如 shbash)不太适合解析 xml 数据。您最好使用xmlstarletxmllint 之类的工具从xml 文件中选择元素并将它们传回shell 进行进一步处理。

    【讨论】:

    • 要求使用 Shell 而不是 xmlstarlet。
    • 你能解释一下'Shell'是什么意思吗?
    猜你喜欢
    • 2021-09-02
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 2013-08-12
    • 2011-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多