# Display the structure of .xml file like a tree

**URL:** <https://community.wolfram.com/t/display-the-structure-of-xml-file-like-a-tree/5674>\
**Category:** Questions\
**Tags:** education\
**Created:** [May 11, 2015, 6:03pm UTC](https://community.wolfram.com/t/display-the-structure-of-xml-file-like-a-tree/5674 "2015-05-11T18:03:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![boudonbenjamin](https://avatars.discourse-cdn.com/v4/letter/b/b5ac83/32.png) [@boudonbenjamin](https://community.wolfram.com/u/boudonbenjamin)\
**Post date:** [May 11, 2015, 6:03pm UTC](https://community.wolfram.com/t/display-the-structure-of-xml-file-like-a-tree/5674/1 "2015-05-11T18:03:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Vitaliyk](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/vitaliyk/32/45591_2.png) [@Vitaliyk](https://community.wolfram.com/u/Vitaliyk)\
**Post date:** [May 11, 2015, 6:33pm UTC](https://community.wolfram.com/t/display-the-structure-of-xml-file-like-a-tree/5674/2 "2015-05-11T18:33:01Z")

</div>

You may want to take a look at this article:

[Advanced Animation in Mathematica: Operating on the Animation Scene Graph in XML (X3D)](http://www.mathematica-journal.com/2013/02/advanced-animation-in-mathematica/)

 ![Dickson_PlacedGraphics_4.gif](https://global.discourse-cdn.com/wolfram/original/3X/3/a/3a0b6816928483eb5aef6a065f716c4b198c59a0.gif)

---

<div class="post-metadata">

**Author:** ![boudonbenjamin](https://avatars.discourse-cdn.com/v4/letter/b/b5ac83/32.png) [@boudonbenjamin](https://community.wolfram.com/u/boudonbenjamin)\
**Post date:** [May 11, 2015, 8:53pm UTC](https://community.wolfram.com/t/display-the-structure-of-xml-file-like-a-tree/5674/3 "2015-05-11T20:53:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![boudonbenjamin](https://avatars.discourse-cdn.com/v4/letter/b/b5ac83/32.png) [@boudonbenjamin](https://community.wolfram.com/u/boudonbenjamin)\
**Post date:** [May 12, 2015, 7:49am UTC](https://community.wolfram.com/t/display-the-structure-of-xml-file-like-a-tree/5674/4 "2015-05-12T07:49:06Z")

</div>

Hello,

In fact, in the help of Mathematica, I have almost find the desired function. This help is available when you look [Transforming XML](http://reference.wolfram.com/language/XML/tutorial/TransformingXML.html).

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

1. May you explain why the XMLNote is a recursive function ?
2. Is the level of hierarchy asked 30 ?
3. Why #1 is used more than # alone ?

Thank for your help

---

<div class="post-metadata">

**Author:** ![samcarrettie](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/samcarrettie/32/29668_2.png) [@samcarrettie](https://community.wolfram.com/u/samcarrettie)\
**Post date:** [May 12, 2015, 5:39pm UTC](https://community.wolfram.com/t/display-the-structure-of-xml-file-like-a-tree/5674/5 "2015-05-12T17:39:46Z")

</div>

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](http://reference.wolfram.com/language/tutorial/FunctionsThatRememberValuesTheyHaveFound.html)

> 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.

---

<div class="post-metadata">

**Author:** ![boudonbenjamin](https://avatars.discourse-cdn.com/v4/letter/b/b5ac83/32.png) [@boudonbenjamin](https://community.wolfram.com/u/boudonbenjamin)\
**Post date:** [May 12, 2015, 6:37pm UTC](https://community.wolfram.com/t/display-the-structure-of-xml-file-like-a-tree/5674/6 "2015-05-12T18:37:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![samcarrettie](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/samcarrettie/32/29668_2.png) [@samcarrettie](https://community.wolfram.com/u/samcarrettie)\
**Post date:** [May 12, 2015, 7:57pm UTC](https://community.wolfram.com/t/display-the-structure-of-xml-file-like-a-tree/5674/7 "2015-05-12T19:57:07Z")

</div>

Perhaps functions like [DeleteCases](http://reference.wolfram.com/language/ref/DeleteCases.html) would help to filter those out?

---

<div class="post-metadata">

**Author:** ![boudonbenjamin](https://avatars.discourse-cdn.com/v4/letter/b/b5ac83/32.png) [@boudonbenjamin](https://community.wolfram.com/u/boudonbenjamin)\
**Post date:** [May 16, 2015, 1:36pm UTC](https://community.wolfram.com/t/display-the-structure-of-xml-file-like-a-tree/5674/8 "2015-05-16T13:36:03Z")

</div>

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
