[jdom-interest] Empty child list

Falk Fraikin fraikin at informatik.tu-darmstadt.de
Tue May 28 02:09:48 PDT 2002


There is a typo in the inner for loop - it should be j.hasNext() not
i.hasNext()...

Rgds,

Falk Fraikin

> -----Ursprungliche Nachricht-----
> Von: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]Im Auftrag von Peter Kelley
> Gesendet: Dienstag, 28. Mai 2002 10:15
> An: jdom-interest at jdom.org
> Betreff: [jdom-interest] Empty child list
>
>
> 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
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yo
uraddr at yourhost.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20020528/3411dbac/attachment.htm


More information about the jdom-interest mailing list