I have imported an XML document into Mathematica. It is now represented as Symbolic XML expression in the variable xml
:
XMLObject["Document"][{XMLObject["Declaration"]["Version" -> "1.0"]},
XMLElement[
"slideshow", {}, {XMLElement["title", {}, {"XML Tutorial"}],
XMLElement[
"slide", {}, {XMLElement["title", {}, {"Agenda"}],
XMLElement["item", {}, {"Introduction"}],
XMLElement["item", {}, {"XML technologies"}],
XMLElement["item", {}, {"Editors for XML documents"}]}]}], {}]
Using the Cases
function I want to extract the XMLElement
expressions whose plain text contents contain the word "XML":
Cases[xml, XMLElement["item", _, {___ ~~ "XML" ~~ ___}], Infinity]
This however returns the empty list, probably because it is mixing a Mathematica expression pattern with a string expression pattern. How does one go about embedding a string pattern into a regular pattern?
*ML
kind of thing. stackoverflow.com/a/1732454/353410 $\endgroup$