简体   繁体   English

使用 Shell 脚本查找 XML 文件的嵌套标签值

[英]Finding nested tag values of XML file using Shell Script

I have an XML file of the format:我有一个格式为 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>

I need to find the value of 'name' tag which is nested inside the /subject/subjects tag.我需要找到嵌套在 /subject/subjects 标记内的“名称”标记的值。 How can I get the values of 'name' tag?如何获取“名称”标签的值?

Shell interpreters (like sh or bash ) are not well suited to parsing xml data. Shell 解释器(如shbash )不太适合解析xml数据。 You would be better off to use a tool like xmlstarlet or xmllint to select elements from an xml file and pass them back to the shell for further processing.您最好使用xmlstarletxmllint之类的工具,将xml文件中的 select 元素传递回 Z2591C98B70119FE624898B1E424B5E19 进行进一步处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM