Testing for an XML attribute
问题 I have a piece of XML like so: <root> <foo src=""/> <foo src="bar"/> <foo /> </root> I want to know which elements have a src attribute , which are empty and which have values. The furthest I have come is with $ xmlstarlet sel -t -m '//foo' -v @src -n foo.xml bar Though that doesn't tell me the third foo is missing the attribute. 回答1: This will select the foos with no src attribute. /root/foo[not(@src)] For the other two tasks, I would use a mix of the expressions pointed out by @TOUDIdel and