【问题标题】:How to retrieve data from an xml file?如何从 xml 文件中检索数据?
【发布时间】:2023-01-20 13:35:16
【问题描述】:

我有以下 xml 文件。在这种情况下,我需要检索 1000 的 apithreshold 值。任何人都知道我怎么能在 Linux 上做到这一点?

<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="OrderQuery" enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.tearDown_on_shutdown">true</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments">
            <elementProp name="secret" elementType="Argument">
              <stringProp name="Argument.name">secret</stringProp>
              <stringProp name="Argument.value">**</stringProp>
              <stringProp name="Argument.metadata">=</stringProp>
            </elementProp>
            <elementProp name="apithreshold" elementType="Argument">
              <stringProp name="Argument.name">apithreshold</stringProp>
              <stringProp name="Argument.value">1000</stringProp>
              <stringProp name="Argument.metadata">=</stringProp>
            </elementProp>
        </collectionProp>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>

【问题讨论】:

  • 你搜索过什么,尝试过什么?

标签: linux xml xmllint


【解决方案1】:
xmllint --xpath '//elementProp[@name="apithreshold"]/stringProp[@name="Argument.value"]/text()' file
-------8<------------------
1000

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多