<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=Windows-1252">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.5762.3">
<TITLE>RE: [jdom-interest] Empty child list</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<P><FONT SIZE=2>There is a typo in the inner for loop - it should be j.hasNext() not i.hasNext()...</FONT>
</P>
<P><FONT SIZE=2>Rgds,</FONT>
</P>
<P><FONT SIZE=2>Falk Fraikin</FONT>
</P>
<P><FONT SIZE=2>> -----Ursprungliche Nachricht-----</FONT>
<BR><FONT SIZE=2>> Von: jdom-interest-admin@jdom.org</FONT>
<BR><FONT SIZE=2>> [<A HREF="mailto:jdom-interest-admin@jdom.org">mailto:jdom-interest-admin@jdom.org</A>]Im Auftrag von Peter Kelley</FONT>
<BR><FONT SIZE=2>> Gesendet: Dienstag, 28. Mai 2002 10:15</FONT>
<BR><FONT SIZE=2>> An: jdom-interest@jdom.org</FONT>
<BR><FONT SIZE=2>> Betreff: [jdom-interest] Empty child list</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Hi,</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> I'm fairly new to JDOM but I think I have something that may be a bug.</FONT>
<BR><FONT SIZE=2>> I'm using the getChildren("name") call to get the children of an</FONT>
<BR><FONT SIZE=2>> element but when the list is examined it is empty. hasChildren("name")</FONT>
<BR><FONT SIZE=2>> is returning true and getChild("name") is returning an element of the</FONT>
<BR><FONT SIZE=2>> correct type. I am using the getChildren("name") successfully in other</FONT>
<BR><FONT SIZE=2>> places in the code.</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Anyone got any ideas ?</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> The code and the output (which shows the input XML) is attatched</FONT>
<BR><FONT SIZE=2>> below...</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> /**</FONT>
<BR><FONT SIZE=2>> * Load journies by XML</FONT>
<BR><FONT SIZE=2>> * @param doc a JDOM document containing journey information</FONT>
<BR><FONT SIZE=2>> * //TODO: put a reference to the schema here</FONT>
<BR><FONT SIZE=2>> * @throws DatabaseException if there was a problem </FONT>
<BR><FONT SIZE=2>> accessing the database</FONT>
<BR><FONT SIZE=2>> * @throws LegServiceNotFoundException if one of the leg </FONT>
<BR><FONT SIZE=2>> services for a </FONT>
<BR><FONT SIZE=2>> * journey is not found</FONT>
<BR><FONT SIZE=2>> */</FONT>
<BR><FONT SIZE=2>> public void loadByXML(Document doc) </FONT>
<BR><FONT SIZE=2>> throws DatabaseException, </FONT>
<BR><FONT SIZE=2>> LegServiceNotFoundException,</FONT>
<BR><FONT SIZE=2>> InvalidJourneyException</FONT>
<BR><FONT SIZE=2>> {</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> // By this stage the document has been validated </FONT>
<BR><FONT SIZE=2>> against the schema so</FONT>
<BR><FONT SIZE=2>> // no input checking is needed</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> Element root = doc.getRootElement();</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> List journies = root.getChildren();</FONT>
<BR><FONT SIZE=2>> log.info("Loading " + journies.size() + " Journey objects");</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> List legServices = null;</FONT>
<BR><FONT SIZE=2>> List legServiceElements = null;</FONT>
<BR><FONT SIZE=2>> Element journeyElement = null;</FONT>
<BR><FONT SIZE=2>> Element legServiceElement = null;</FONT>
<BR><FONT SIZE=2>> Journey journey = null;</FONT>
<BR><FONT SIZE=2>> LegService legService = null;</FONT>
<BR><FONT SIZE=2>> String name = null;</FONT>
<BR><FONT SIZE=2>> long id = 0;</FONT>
<BR><FONT SIZE=2>> long serviceID = 0;</FONT>
<BR><FONT SIZE=2>> long legID = 0;</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> LegServiceDAO lsDAO = new LegServiceDAO(session);</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> for (Iterator i = journies.iterator();i.hasNext();) {</FONT>
<BR><FONT SIZE=2>> try {</FONT>
<BR><FONT SIZE=2>> journeyElement = (Element)(i.next());</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> id = </FONT>
<BR><FONT SIZE=2>> Long.parseLong(journeyElement.getAttributeValue("id"));</FONT>
<BR><FONT SIZE=2>> name = journeyElement.getAttributeValue("name");</FONT>
<BR><FONT SIZE=2>> journey = new Journey(id, name);</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> log.debug("" + journeyElement.hasChildren());</FONT>
<BR><FONT SIZE=2>> log.debug("" + journeyElement.getChild("legService"));</FONT>
<BR><FONT SIZE=2>> legServiceElements = </FONT>
<BR><FONT SIZE=2>> journeyElement.getChildren("legService");</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> for (Iterator j = </FONT>
<BR><FONT SIZE=2>> legServiceElements.iterator();i.hasNext();) {</FONT>
<BR><FONT SIZE=2>> legServiceElement = (Element)(j.next());</FONT>
<BR><FONT SIZE=2>> legID = Long.parseLong(</FONT>
<BR><FONT SIZE=2>> legServiceElement.getAttributeValue("legID"));</FONT>
<BR><FONT SIZE=2>> serviceID = Long.parseLong(</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> legServiceElement.getAttributeValue("serviceID"));</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> legService = </FONT>
<BR><FONT SIZE=2>> lsDAO.findByLegAndServiceID(legID, serviceID);</FONT>
<BR><FONT SIZE=2>> if (legService == null) {</FONT>
<BR><FONT SIZE=2>> throw new LegServiceNotFoundException(</FONT>
<BR><FONT SIZE=2>> "LegService with leg id " + legID +</FONT>
<BR><FONT SIZE=2>> " and service id " + serviceID + </FONT>
<BR><FONT SIZE=2>> " not found");</FONT>
<BR><FONT SIZE=2>> }</FONT>
<BR><FONT SIZE=2>> log.debug("Adding leg service " + legService);</FONT>
<BR><FONT SIZE=2>> journey.addLegService(legService);</FONT>
<BR><FONT SIZE=2>> }</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> log.debug("Adding journey " + journey);</FONT>
<BR><FONT SIZE=2>> create(journey);</FONT>
<BR><FONT SIZE=2>> } catch (NumberFormatException e) {</FONT>
<BR><FONT SIZE=2>> log.error("Error parsing number whilst importing",e);</FONT>
<BR><FONT SIZE=2>> }</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> }</FONT>
<BR><FONT SIZE=2>> log.debug("Finished loading journies");</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> }</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> 17:51:51,859 INFO [DAOHelper] Loading XML from file </FONT>
<BR><FONT SIZE=2>> c:/source/projects/moveit/tests/data/xml\journey.xml</FONT>
<BR><FONT SIZE=2>> 17:51:51,869 DEBUG [DAOHelper] Loaded XML from file </FONT>
<BR><FONT SIZE=2>> c:/source/projects/moveit/tests/data/xml\journey.xml</FONT>
<BR><FONT SIZE=2>> 17:51:51,869 DEBUG [DAOHelper] <?xml version="1.0" encoding="UTF-8"?></FONT>
<BR><FONT SIZE=2>> <!-- Created by Administrator on 27 May 2002, 17:58 --><journies></FONT>
<BR><FONT SIZE=2>> <journey name="journey 1" id="1"></FONT>
<BR><FONT SIZE=2>> <legService legID="2" serviceID="1" /></FONT>
<BR><FONT SIZE=2>> <legService legID="6" serviceID="1" /></FONT>
<BR><FONT SIZE=2>> <legService legID="5" serviceID="1" /></FONT>
<BR><FONT SIZE=2>> </journey></FONT>
<BR><FONT SIZE=2>> </journies></FONT>
<BR><FONT SIZE=2>> 17:51:51,889 INFO [JourneyDAO] Loading 1 Journey objects</FONT>
<BR><FONT SIZE=2>> 17:51:51,889 DEBUG [JourneyDAO] true</FONT>
<BR><FONT SIZE=2>> 17:51:51,889 DEBUG [JourneyDAO] [Element: <legService/>]</FONT>
<BR><FONT SIZE=2>> 17:51:51,889 DEBUG [JourneyDAO] Adding journey </FONT>
<BR><FONT SIZE=2>> Journey[id=1;name=journey 1]</FONT>
<BR><FONT SIZE=2>> 17:51:51,889 DEBUG [JourneyDAO] Finished loading journies</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> -- </FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> regards,</FONT>
<BR><FONT SIZE=2>> Peter Kelley</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> MoveIt Pty Ltd </FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> "If you want to build a ship, don't drum up the men to</FONT>
<BR><FONT SIZE=2>> gather wood, divide the work and give orders. Instead, </FONT>
<BR><FONT SIZE=2>> teach them to yearn for the vast and endless sea."</FONT>
<BR><FONT SIZE=2>> - Saint-Exupery</FONT>
<BR><FONT SIZE=2>> </FONT>
<BR><FONT SIZE=2>> _______________________________________________</FONT>
<BR><FONT SIZE=2>> To control your jdom-interest membership:</FONT>
<BR><FONT SIZE=2>> <A HREF="http://lists.denveronline.net/mailman/options/jdom-interest/yo">http://lists.denveronline.net/mailman/options/jdom-interest/yo</A></FONT>
<BR><FONT SIZE=2>uraddr@yourhost.com</FONT>
</P>
</BODY>
</HTML>