我使用Ansible playbook从一个XML文件中提取一个特定的属性值,如the Ansible XML module page中所述,但是得到一个错误“Xpath/business/website/validxhtml不引用节点”。
XML文件:
<business type="bar">
<name>Tasty Beverage Co.</name>
<beers>
<beer>Rochefort 10</beer>
<beer>St. Bernardus Abbot 12</beer>
<beer>Schlitz</beer>
</beers>
<rating subjective="true">10</rating>
<website>
<mobilefriendly/>
<address>http://tastybeverageco.com</address>
</website>
</business>
YAML文件:
^{pr2}$回应:
PLAY [testing XMl values] ************************************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************************
ok: [localhost]
TASK [Read an element's attribute values] ********************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Xpath /business/website/validxhtml does not reference a node!"}
PLAY RECAP ***************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
我使用的示例和Ansible xml页面中指定的相同,但不确定它失败的原因。请帮助。
这是因为示例xml中既不存在}。首先,类似于XML的HTML有元素和属性,两者都是不同的东西Ref
validxhtml
元素,也不存在{因此,您需要添加带有要提取的属性值的
validxhtml
元素,或者在xml文件中使用其他具有属性例如<rating subjective="true">10</rating>
的元素。我希望这有帮助。在[更新] 如请求的那样,如果您只想获得元素值,只需尝试它应该返回
10
。在相关问题 更多 >
编程相关推荐