Unless I'm missing some detail, I believe your problem lies with the XPath expression you're using:

Element name = (Element) car.selectSingleNode("./car/name");

you have a car element, and the xpath says "select the name element, of each car child element within the given car". Which would match the name element in the following document:


        <cars>
                <car>
                        <car>
                                <name>name</name>
                        </car>
                </car>
        </cars>

so what you want is just to select the name element beneath the current car:

Element name = (Element)car.selectSingleNode("name");

By the way, the speedier way of getting the name text would be:

String name = car.elementText("name");

or to get the element:

Element name = car.element("name");

This way, you needn't parse and execute a whole XPath, just iterate through the internal List.

christian.



-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to