Issue with Dom4j parser

Hi All,

I am trying to parse the below XMLfile using org.dom4j api.

I am using the below code to parse this

SAXReader saxReader = new SAXReader();
            Document document = saxReader.read(new File("C://ecllipse//workspace//Hybernate//input//portal.xml"));
            List list = document.selectNodes("//taxonomy/*");

Iterator iter = list.iterator();

            while (iter.hasNext()) {
                     Object obj= iter.next();
//                     org.dom4j.tree.DefaultElement element = (org.dom4j.tree.DefaultElement) obj;

                     System.out.println(obj.getClass());
                     System.out.println(obj);
                  }


In the above script, when I do sysout of the obj, i am getting only frist level tag information under "Taxonomy" tag. What I want is that, each time i get a category tag as "obj", i want the complete tree under the category tag to be available in "obj"

Can any one provide some pointers to this
*********************************************************************************************
<?xml version="1.0" encoding="ISO-8859-1"?>

    <taxonomy name="Portal_TX" className="Generic" type="taxonomy"
        internalId="12345" taxonomyVersion="1.0">
        <details title="Portal Taxonomy">
            <description></description>
            <owners>
                <owner name="testuser"/>
            </owners>
            <operations/>
            <languageInfo/>
        </details>
        <category name="Portal_Category1" className="Generic"
            type="category" internalId="32423423">
            <details title="testing">
                <description></description>
                <owners>
                    <owner name="testuser"/>
                </owners>
                <operations/>
                <languageInfo/>
            </details>
        </category>
        <category name="Portal_Category2" className="Generic"
            type="category" internalId="234324234">
            <details title="">
                <description></description>
                <owners>
                    <owner name="testuser"/>
                </owners>
                <operations/>
                <languageInfo/>
            </details>
        </category>
    </taxonomy>
*********************************************************************************
srinivasysr2003Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ajay-SinghCommented:
> System.out.println(obj);

It calls to toString of obj, which prints just the node its on. To print the
whole tree, you should use the following:
 
    OutputFormat format = OutputFormat.createPrettyPrint();

    XMLWriter writer = new XMLWriter( out, format );

    writer.write( document );

    writer.close();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.