[jdom-interest] Empty child list

Ian Lea ian at digimem.net
Tue May 28 02:52:38 PDT 2002


Try replacing the i.hasNext() is this line:

 for (Iterator j = legServiceElements.iterator();i.hasNext();) {

with j.hasNext().



--
Ian.
ian at digimem.net



> peterk at moveit.com.au (Peter Kelley) wrote 
>
> Hi,
> 
> I'm fairly new to JDOM but I think I have something that may be a bug.
> I'm using the getChildren("name") call to get the children of an
> element but when the list is examined it is empty. hasChildren("name")
> is returning true and getChild("name") is returning an element of the
> correct type. I am using the getChildren("name") successfully in other
> places in the code.
> 
> Anyone got any ideas ?
> 
> The code and the output (which shows the input XML) is attatched
> below...
> 
>     /**
>      * Load journies by XML
>      * @param doc a JDOM document containing journey information
>      * //TODO: put a reference to the schema here
>      * @throws DatabaseException if there was a problem accessing the database
>      * @throws LegServiceNotFoundException if one of the leg services for a 
>      * journey is not found
>      */
>     public void loadByXML(Document doc) 
>         throws DatabaseException, 
>                LegServiceNotFoundException,
>                InvalidJourneyException
>     {
>         
>         // By this stage the document has been validated against the schema so
>         // no input checking is needed
>         
>         Element root = doc.getRootElement();
>         
>         List journies = root.getChildren();
>         log.info("Loading " + journies.size() + " Journey objects");
> 
>         List legServices = null;
>         List legServiceElements = null;
>         Element journeyElement = null;
>         Element legServiceElement = null;
>         Journey journey = null;
>         LegService legService = null;
>         String name = null;
>         long id = 0;
>         long serviceID = 0;
>         long legID = 0;
>         
>         LegServiceDAO lsDAO = new LegServiceDAO(session);
>         
>         for (Iterator i = journies.iterator();i.hasNext();) {
>             try {
>                 journeyElement = (Element)(i.next());
>                 
>                 id = Long.parseLong(journeyElement.getAttributeValue("id"));
>                 name = journeyElement.getAttributeValue("name");
>                 journey = new Journey(id, name);
>                 
>                 log.debug("" + journeyElement.hasChildren());
>                 log.debug("" + journeyElement.getChild("legService"));
>                 legServiceElements = journeyElement.getChildren("legService");
>                 
>                 for (Iterator j = legServiceElements.iterator();i.hasNext();) {
>                     legServiceElement = (Element)(j.next());
>                     legID = Long.parseLong(
>                         legServiceElement.getAttributeValue("legID"));
>                     serviceID = Long.parseLong(
>                         legServiceElement.getAttributeValue("serviceID"));
>                     
>                     legService = lsDAO.findByLegAndServiceID(legID, serviceID);
>                     if (legService == null) {
>                         throw new LegServiceNotFoundException(
>                             "LegService with leg id " + legID +
>                             " and service id " + serviceID + " not found");
>                     }
>                     log.debug("Adding leg service " + legService);
>                     journey.addLegService(legService);
>                 }
>                 
>                 log.debug("Adding journey " + journey);
>                 create(journey);
>             } catch (NumberFormatException e) {
>                 log.error("Error parsing number whilst importing",e);
>             }
>             
>         }
>         log.debug("Finished loading journies");
>         
>     }
> 
> 17:51:51,859 INFO  [DAOHelper] Loading XML from file c:/source/projects/moveit/tests/data/xml\journey.xml
> 17:51:51,869 DEBUG [DAOHelper] Loaded XML from file c:/source/projects/moveit/tests/data/xml\journey.xml
> 17:51:51,869 DEBUG [DAOHelper] <?xml version="1.0" encoding="UTF-8"?>
> <!-- Created by Administrator on 27 May 2002, 17:58 --><journies>
>     <journey name="journey 1" id="1">
>         <legService legID="2" serviceID="1" />
>         <legService legID="6" serviceID="1" />
>         <legService legID="5" serviceID="1" />
>     </journey>
> </journies>
> 17:51:51,889 INFO  [JourneyDAO] Loading 1 Journey objects
> 17:51:51,889 DEBUG [JourneyDAO] true
> 17:51:51,889 DEBUG [JourneyDAO] [Element: <legService/>]
> 17:51:51,889 DEBUG [JourneyDAO] Adding journey Journey[id=1;name=journey 1]
> 17:51:51,889 DEBUG [JourneyDAO] Finished loading journies
> 
> 
> -- 
> 
> regards,
> Peter Kelley
> 
> MoveIt Pty Ltd    
> 
> "If you want to build a ship, don't drum up the men to
> gather wood, divide the work and give orders. Instead, 
> teach them to yearn for the vast and endless sea."
> - Saint-Exupery


----------------------------------------------------------------------
Searchable personal storage and archiving from http://www.digimem.net/


More information about the jdom-interest mailing list