Grepping XML works until the day a tag is split over two lines. xmllint, which ships with libxml2, can run a real XPath query instead and print only what matched.
xmllint --xpath '//book/title/text()' feed.xml
The help text for --xpath expr says it evaluates an XPath expression and implies --noout, so only the result is printed. Take a small file with three <book> elements, each with an id attribute and a <title> and <price>. On libxml 2.9.14 the queries below printed this:
xmllint --xpath 'string(//book[@id="b2"]/title)' feed.xml
Hyperion
xmllint --xpath 'count(//book)' feed.xml
3
xmllint --xpath 'sum(//price)' feed.xml
29.75
xmllint --xpath '//book[price>9]/title/text()' feed.xml
Dune
Hyperion
Wrapping the path in string() gives one plain value, which is what a shell variable wants. Without it, an attribute comes out with its name, for example id="b2".
Two caveats. First, when nothing matches, xmllint prints XPath set is empty and exits with status 10, so a script can tell “no match” from an empty string.
Second, namespaces. A document with a default namespace, like an Atom feed, makes //entry/title match nothing. A prefix you invent, such as //a:title, fails with Undefined namespace prefix. This worked on such a feed:
xmllint --xpath '//*[local-name()="title"]/text()' feed.xml
It ignores the namespace and matches on the element name only. Ugly, but short enough for a one-off.
Further reading: xmllint man page