# How to dynamically parse xml?

**URL:** <https://forum.kirupa.com/t/how-to-dynamically-parse-xml/261819>\
**Category:** Uncategorized\
**Created:** [May 31, 2008, 8:20am UTC](https://forum.kirupa.com/t/how-to-dynamically-parse-xml/261819 "2008-05-31T08:20:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohbeewan](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ohbeewan/32/1745_2.png) [@ohbeewan](https://forum.kirupa.com/u/ohbeewan)\
**Post date:** [May 31, 2008, 8:20am UTC](https://forum.kirupa.com/t/how-to-dynamically-parse-xml/261819/1 "2008-05-31T08:20:05Z")

</div>

Hmm,

Pretty new to parsing xml. I’m trying to get my head around parsing this xml structure dynamically so that I don’t have to know which elements have children in advance of parsing the xml.

Here’s the structure:

```auto

<menu>
    <item name="portfolio">
        <item name="sketches">
            <item name="blackOnWhite">
                <detail image="1.jpg"/>
                <detail image="2.jpg"/>
            </item>
        </item>
        <item name="paintings">
            <item name="oil">
                <detail image="1.jpg"/>
                <detail image="2.jpg"/>
            </item>
            <item name="acrylic">
                <detail image="1.jpg"/>
            </item>
        </item>
        <item name="mixed medium">
            <detail image="1.jpg"/>
        </item>
    </item>
</menu>

```

I tried using loops with hasChildNodes() and while (firstChild != null), but I can’t find the logic. Any pointers would be greatly appreciated!

Much respect!

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [June 1, 2008, 6:50pm UTC](https://forum.kirupa.com/t/how-to-dynamically-parse-xml/261819/2 "2008-06-01T18:50:08Z")

</div>

well… this was an attempt… try it… the possible xml structure is mentioned in the class file itself as a comment

[http://www.4shared.com/file/49750406/7ba77b7d/xmlObject.html](http://www.4shared.com/file/49750406/7ba77b7d/xmlObject.html)

---

<div class="post-metadata">

**Author:** ![randomagain](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@randomagain](https://forum.kirupa.com/u/randomagain)\
**Post date:** [June 2, 2008, 8:34am UTC](https://forum.kirupa.com/t/how-to-dynamically-parse-xml/261819/3 "2008-06-02T08:34:55Z")

</div>

erm there is a tutorial on the main page of this web site

strange as it seems

plus you should call your tags different things, item everywhere isn’t obvious which tag belongs to which

---

<div class="post-metadata">

**Author:** ![sparkdemon](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sparkdemon](https://forum.kirupa.com/u/sparkdemon)\
**Post date:** [June 25, 2008, 11:13am UTC](https://forum.kirupa.com/t/how-to-dynamically-parse-xml/261819/4 "2008-06-25T11:13:57Z")

</div>

Well sorry to be re invoking this thread… but i got the final solution that most of you want…  
Use ASAP frame work’s xml2Object for parsing anytype of xml… in just 1 line… 🙂

[http://asapframework.org/api/html/org\_asapframework\_util\_xml\_XML2Object.html](http://asapframework.org/api/html/org_asapframework_util_xml_XML2Object.html)

the frame work is free and can be downloaded from [http://asapframework.org/](http://asapframework.org/)
