如何解决xmllint不返回我期望的结果-n00b警告
问题>我从存储在get_build_info.xml中的API调用返回了一些xml。我试图从该XML中获取一个属性,build_id。这是xml:
<?xml version="1.0" encoding="UTF-8"?>
<buildinfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://analysiscenter.veracode.com/schema/4.0/buildinfo" xsi:schemaLocation="https://analysiscenter.veracode.com/schema/4.0/buildinfo https://analysiscenter.veracode.com/resource/4.0/buildinfo.xsd" buildinfo_version="1.4" account_id="1234" app_id="010101" sandbox_id="020202" build_id="987654321"><build version="4 Sep 2020 Static (2)" build_id="987654321" submitter="Someone Else" platform="Not Specified" lifecycle_stage="Not Specified" results_ready="true" policy_name="Some Development App Policy" policy_version="7" policy_compliance_status="Conditional Pass" rules_status="Not Assessed" grace_period_expired="false" scan_overdue="false" legacy_scan_engine="false">
<analysis_unit analysis_type="Static" published_date="2020-09-04T11:44:09-04:00" published_date_sec="1599234249" status="Results Ready" engine_version="20200821190810"/>
</build>
</buildinfo>
我尝试过的内容>以下内容及其许多其他变体:
xmllint --xpath 'string(//xml/buildinfo/@build_id)' get_build_info.xml
xmllint --xpath 'string(//buildinfo/@build_id)' get_build_info.xml
xmllint --xpath 'string(/xml/buildinfo/@build_id)' get_build_info.xml
xmllint --xpath '(//xml/buildinfo/build_id/text())' get_build_info.xml
xmllint --xpath '(/xml/buildinfo/build_id/text())' get_build_info.xml
最后两个至少产生某种输出,尽管“ XPath set为空”。我在--xpath中使用'string(+ ... + @build_id的前几个地方,我什么也没得到。这些东西似乎也都从bash退出了0,所以我没有语法问题就像我说的,我是n00b。我在stackoverflow上查看了其他流行的票证,这就是让我明白这一点的原因,我很可能在这里没有考虑到明显的事情,所以假设我对bash一无所知(几乎是对的)。我很高兴能得到一个指示,让我自己找到答案。
解决方法
您将被命名空间所困扰,因此请尝试使用xpath表达式,例如:
//*[local-name()='buildinfo']/@build_id
看看是否可行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。