I would like to retrieve the XML Tree of a XMLObject
with only specific XMLElements
.
In the help of Mathematica TransformingXML, a function called XMLNote
is given and enables me to retrieve the XML Tree.
Here is the mentioned function :
XMLNote[XMLElement[tag_, attributes_, data_], m_Integer] :=
Cell[CellGroupData[{
Cell[TextData[
StyleBox[tag, FontFamily -> "Swiss",
FontWeight -> "Bold", FontSize -> 15]]],
Sequence @@ (XMLNote[#1, m] &) /@ attributes,
Sequence @@ (XMLNote[#1, m + 30] &) /@ data
}, Open],
CellMargins -> {{m, Inherited}, {Inherited, Inherited}}]
XMLNote[{an_String, a_String} -> v_String, m_Integer] :=
Cell[TextData[{
StyleBox[an, FontColor -> Hue[0.6]], " ",
StyleBox[a, FontWeight -> "Bold"], " = ",
StyleBox[v, Background -> GrayLevel[0.8]]}],
CellMargins -> {{m + 5, Inherited}, {Inherited, Inherited}}]
XMLNote[a_String -> v_String, m_Integer] :=
Cell[TextData[{
StyleBox[a, FontWeight -> "Bold"], " = ",
StyleBox[v, Background -> GrayLevel[0.8]]}],
CellMargins -> {{m + 5, Inherited}, {Inherited, Inherited}}]
XMLNote[s_String, m_Integer] :=
Cell[s, Background -> GrayLevel[0.9],
CellMargins -> {{m + 25, Inherited}, {Inherited, Inherited}}]
In my XMLObject
, I would like to retrieve only the XML tree limited to the XMLElements
called "Section"
and "TextHeading"
.
May you help me to reduce my tree to some specific XMLElements
?
Here a example for experimenting :
'XMLObject["Document"][{},
XMLElement[
"math", {{"http://www.w3.org/2000/xmlns/", "xmlns"} ->
"http://www.w3.org/1998/Math/MathML"}, {XMLElement[
"semantics", {}, {XMLElement[
"mfrac", {}, {XMLElement["mn", {}, {"1"}],
XMLElement["msqrt", {}, {XMLElement["mn", {}, {"2"}]}]}],
XMLElement[
"annotation-xml", {"encoding" -> "MathML-Content"}, {XMLElement[
"section", {}, {XMLElement["times", {}, {}],
XMLElement["TextHeading", {"type" -> "integer"}, {"1"}],
XMLElement[
"section", {}, {XMLElement["power", {}, {}],
XMLElement[
"section", {}, {XMLElement["power", {}, {}],
XMLElement["TextHeading", {"type" -> "integer"}, {"2"}],
XMLElement[
"TextHeading", {"type" -> "rational"}, {"1",
XMLElement["sep", {}, {}], "2"}]}],
XMLElement[
"TextHeading", {"type" ->
"integer"}, {"-1"}]}]}]}]}]}], {}]'
Thank you for your help