Extract value from xml file with namespaces by using xmllint in bash

不问归期 提交于 2019-12-06 11:57:01

Your file uses namespaces (xmlns). To be independent of these, I suggest:

xmllint --xpath "//*[local-name()='widget']/*[local-name()='name']/text()" config.xml

Output:

Product Finder

Notice that not only the element where the default namespace is declared resides in that namespace, but all descendant elements without prefix and without local default namespace implicitly inherit the default namespace from the ancestor. This means you also need to use the prefix x to reference name element since it inherits the default namespace from widget :

/ > xpath /x:widget/x:name/text()[1]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!