JDOM element error

  • Thread starter steve_marjoribanks
  • Start date
S

steve_marjoribanks

The code below shows part of a method from my code. Everything compiles
fine apart from one error which says:


cannot find symbol
symbol: method getChildren(java.lang.String)
location: interface java.util.List
List content =
element.getChildren("interpretedData")

^


I don't see what's wrong though because it seems to be saying I can't
use the String as an argument but from what I can work out, I've stuck
to the method shown in the JDOM API
http://www.jdom.org/docs/apidocs/org/jdom/Element.html#getChildren(java.lang.String)
Any ideas? Thanks

Steve



public void process(Element element)
{
int numberOfPoints;

try
{
List content = element.getChildren("interpretedData")
.getChildren("Slope")
.getChildren("groundProfile")
.getChildren("groundSurface")
.getChildren("Line")
.getChildren("Points");
numberOfPoints = content.size();
groundSurfacePointsX = new float[numberOfPoints];
groundSurfacePointsY = new float[numberOfPoints];
int i=0;
 
T

Tajonis

My first question back to you would be which version of JDOM are you
using?

Here is a code snippet that I am currently using with JDOM 1.0 and it
works great.

Iterator valueIterator = filterElement.getChildren("value").iterator();
String values = "";

while(valueIterator.hasNext()){
Element valueElement = (Element)valueIterator.next();
values += valueElement.getAttributeValue("value") + ";";
}

The one thing I would make sure of is that (because ive run into
problems on UNIX) is this comment direct from JDOM FAQ:

What's wrong?

You need to ensure that the xerces.jar file supplied with the JDOM
download is in your classpath before any other XML classes, such as
those that come with JAXP or Crimson. These other XML libraries, as
well as older versions of Apache Xerces, support DOM Level 1 and SAX
1.0, not the required DOM Level 2 and SAX 2.0. The result is an
exception being thrown. Check your classpath, and try again. If the
classpath looks OK, the problematic JAR might also be hiding in the
system's standard extension directory (see the following).

Other than that I would suggest not using
Element.getChildren("name").getChildren("name").getChildren("name").getChildren("name")

But instead iterating over the List that is returned for each
..getChildren("name") call.
 
S

steve_marjoribanks

I'm using JDOM 1.0 and I checked my classpath and tried it again but
it's still reporting the same error.

I could try and re-code it in a different way but the thing is that I
need to carry out a few similar statements and if I iterate over each
list returned from the getChildren methods it will make my code much
longer.
However, I'm not even sure this is the problem because as shown in the
error report which I gave above, it is flagging the very first
getChildren() method and seems to have a problem with an
element.getChildren(java.lang.String) method returning a list even
though it is supposed to do exactly that according to the API?!

Steve
 
J

James Westby

I'm using JDOM 1.0 and I checked my classpath and tried it again but
it's still reporting the same error.

I could try and re-code it in a different way but the thing is that I
need to carry out a few similar statements and if I iterate over each
list returned from the getChildren methods it will make my code much
longer.
However, I'm not even sure this is the problem because as shown in the
error report which I gave above, it is flagging the very first
getChildren() method and seems to have a problem with an
element.getChildren(java.lang.String) method returning a list even
though it is supposed to do exactly that according to the API?!

Steve
The problem is not the first invocation, it is all the chained invocations.

If these are split out then your code would look like

List firstChildren = element.getChildren("...

List secondChildren = firstChildren.getChildren("...

However you can see that you are calling the getChildren method of List
in the second line, and this method does not exist. You need to call the
method on ech of the members of firstChildren, and so iterate in some
fashion.


James
 
S

steve_marjoribanks

Is it not possible to navigate straight to an element by using names
then? Is it necessary to iterate through the list of child elements at
every level of the XML tree?

Steve
 
J

James Westby

Is it not possible to navigate straight to an element by using names
then? Is it necessary to iterate through the list of child elements at
every level of the XML tree?

Steve
But which element do you want? The first one with that name, the last
one, a collection of all of them, or the next one since you last called it?

Have a look at Filter ans ElementFilter in JDOM, they might do what you
want.

Or look at XPath, there is some in JDOM now, that might do it also.


James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top