Hello,
I would like to retrieve some labels in .xml file.
This code XmlData = Import["...", "XML"] enables me to have access to a XMLObject.
I would like to like to have now a display of the structure of my XMLObject, a but as it is possible with TreeForm on a functional expression.
Is there a function to display the structure of XMLObject ?
Thank you for your help.
Vitaliyk
(Vitaliy Kaurov)
May 11, 2015, 6:33pm
2
Very interesting. It is exactly what I’m looking for.
However, I didn’t manage to use efficiently ExpressionTreePlot
In my XMLObject, I have some XMLElements which have big arguments like this :
XMLElement["Equation", {"executable" -> "false", "style" -> "2D Math",
"input-equation" -> "",
"display" ->
"LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYk\
dGJzYmLUkjbW9HRiQ2LVEhRicvJSxtYXRodmFyaWFudEdRJ25vcm1hbEYnLyUmZmVuY2VH\
USZmYWxzZUYnLyUqc2VwYXJhdG9yR0Y0LyUpc3RyZXRjaHlHRjQvJSpzeW1tZXRyaWNHRj\
QvJShsYXJnZW9wR0Y0LyUubW92YWJsZWxpbWl0c0dGNC8lJ2FjY2VudEdGNC8lJ2xzcGFj\
ZUdRLDAuMjIyMjIyMmVtRicvJSdyc3BhY2VHRkMtRiM2JkYrLUYjNigtSSNtaUdGJDYoUS\
9Jbml0aWFsaXNhdGlvbkYnLyUlc2l6ZUdRIzE2RicvJSVib2xkR1EldHJ1ZUYnLyUnaXRh\
bGljR0Y0L0YwUSVib2xkRicvJStmb250d2VpZ2h0R0ZXLUYsNi1RMSZJbnZpc2libGVUaW\
1lcztGJ0YvRjJGNUY3RjlGO0Y9Rj8vRkJRJjAuMGVtRicvRkVGaG4tRks2KFEkZGVzRidG\
TkZRRlRGVkZYRlotRks2KFEqdmFyaWFibGVzRidGTkZRRlRGVkZYRi9GK0YvRitGLw=="}\
, {"LUklbXJvd0c2Iy9JK21vZHVsZW5hbWVHNiJJLFR5cGVzZXR0aW5nR0koX3N5c2xpYk\
dGJzYmLUkjbW9HRiQ2LVEhRicvJSxtYXRodmFyaWFudEdRJ25vcm1hbEYnLyUmZmVuY2VH\
USZmYWxzZUYnLyUqc2VwYXJhdG9yR0Y0LyUpc3RyZXRjaHlHRjQvJSpzeW1tZXRyaWNHRj\
QvJShsYXJnZW9wR0Y0LyUubW92YWJsZWxpbWl0c0dGNC8lJ2FjY2VudEdGNC8lJ2xzcGFj\
ZUdRLDAuMjIyMjIyMmVtRicvJSdyc3BhY2VHRkMtRiM2JkYrLUYjNigtSSNtaUdGJDYoUS\
9Jbml0aWFsaXNhdGlvbkYnLyUlc2l6ZUdRIzE2RicvJSVib2xkR1EldHJ1ZUYnLyUnaXRh\
bGljR0Y0L0YwUSVib2xkRicvJStmb250d2VpZ2h0R0ZXLUYsNi1RMSZJbnZpc2libGVUaW\
1lcztGJ0YvRjJGNUY3RjlGO0Y9Rj8vRkJRJjAuMGVtRicvRkVGaG4tRks2KFEkZGVzRidG\
TkZRRlRGVkZYRlotRks2KFEqdmFyaWFibGVzRidGTkZRRlRGVkZYRi9GK0YvRitGLw=="}\
]
Consequently, I didn’t manage to have a concise tree, easy to visualize.
How can I do to ask all the structure with only the names of the XMLElements but not all the details about their properties in order to be able to visualize it ?
Thanks a lot for your help
Hello,
In fact, in the help of Mathematica, I have almost find the desired function. This help is available when you look Transforming XML .
Here is the beginning of the code :
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}}]
However, I have still difficulty to understand the code and namely these two lines :
Sequence @@ (XMLNote[#1, m] &) /@ attributes,
Sequence @@ (XMLNote[#1, m + 30] &) /@ data
Questions
May you explain why the XMLNote is a recursive function ?
Is the level of hierarchy asked 30 ?
Why #1 is used more than # alone ?
Thank for your help
This is a very nice find, thanks for posting! Some perhaps vague answers:
May you explain why the XMLNote is a recursive function ?
Because in Wolfram Language (WL) functions that refers to itself is recursive see:
Functions That Remember Values They Have Found
Is the level of hierarchy asked 30 ?
Not sure what you mean, but probably yes - I think this how far back recursive function looks.
Why #1 is used more than # alone ?
# and #1 are the same things - just matter of personal code style preference.
In[8]:= #^2 & /@ {1, 2, 3}
Out[8]= {1, 4, 9}
In[9]:= #1^2 & /@ {1, 2, 3}
Out[9]= {1, 4, 9}
Hope this helps.
Thanks a lot for your clear answers.
In order to be able to use ExpressionTreePlot on my XMLObject, one idea is to suppress all the attributes of the XMLElements inside the XMLObject which take a lot of space.
May you help me to define the code so as to suppress all the attributes of my XMLElements inside the XMLObject ?
Thank you for your help.
Perhaps functions like DeleteCases would help to filter those out?
I try this code to delete all the attributes of my XMLElements
XMLtest =
Block[{XMLElement},
XMLElement[tag_, _, content_] := XMLElement[tag, {}, content]; XMLtest]
but it doesn’t work, I receive this error message
$IterationLimit::itlim: Iteration limit of 4096 exceeded. >>
General::stop: Further output of $IterationLimit::itlim will be suppressed during this calculation. >>
May you help me to define the code so as to suppress all the attributes of my XMLElements inside the XMLObject ?
Thank you for your help.
P.S: Thank you Kuba for your help