How to dynamically parse xml?

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:


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

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

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

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… :slight_smile:

http://asapframework.org/api/html/org_asapframework_util_xml_XML2Object.html

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