[jdom-interest] simple question

newsham at hotu.com newsham at hotu.com
Tue Jul 31 16:52:48 PDT 2001


In Java, a class is specified by a hierarchical name, i.e., org.jdom.Element.  You must always refer to an object type by its full name, unless
(1) it's in the java.lang package, or (2) you "import" the class name ("import" may sound misleading; its only purpose is convenience -- to
allow you to refer to a class with a shorter name).

"import org.jdom.Element;" allows you to refer to the class simply as Element (although it is STILL the same class, namely org.jdom.Element).
You can also import the entire package with "import org.jdom.*".  This allows you to refer to all classes in the org.jdom package (but not
subpackages such as org.jdom.output) as their simple names, including org.jdom.Element.


Justin Wall wrote:

>          Thanks for the reply!  I'm not importing the w3c package.  I have
> one demo I've written from some online examples and in that I just needed
> to use "Element" to describe a JDOM element, as in "public static String
> InsertActionParser(Element ia)".  However, now I'm writing a seperate class
> of my own and I can't do the same thing without the compiler returning an
> error about the passed variable.  To fix it I used "org.jdom.Element".  I
> don't understand why.
>
> I'm wondering if these lines in the demo had something to do with it:
>
>                  /** Test getting DOM Element from JDOM Element*/
>                  org.w3c.dom.Element domElement =
> domOutputter.output(xtfDoc.getRootElement());
>                  /** Test getting JDOM Element from DOM Element*/
>                  org.jdom.Element jdomElement = domBuilder.build(domElement);
>
>                  Element Actions = jdomElement.getChild("Actions");
>                  ^
>                  (notice I didn't have to use org.jdom.Element here)
>
> Did getting the root element and building a DOM allow "Element" to be used?
>
> This is what my new class uses:
>
>                  import org.jdom.*;
>                  import java.util.*;
>
>                  public class deleteAction
>                  {
>                          /** constructors */
>                          /******************************************************************************************************************
>                           * parser constructor for deleteAction element
>                           * takes an element as defined by JDOM and builds
> deleteAction object
>                           ******************************************************************************************************************/
>                          public deleteAction(org.jdom.Element d)
>                          {
>
> Thanks again,
>
> Justin
>
> At 03:31 PM 7/31/01 -0700, you wrote:
> >If you are importing the org.w3c.dom package in your class, then replace
> >
> >public static List tablesParser(org.w3c.dom.Element tb1)
> >
> >-----Original Message-----
> >From: Justin Wall [mailto:jwall at interactivesites.com]
> >Sent: Tuesday, July 31, 2001 3:21 PM
> >To: jdom-interest at jdom.org
> >Subject: [jdom-interest] simple question
> >
> >
> >
> >         Sorry about this, I'm also new to Java, but  was wondering how
> >to do
> >this.  How can I just use "Element" as a class descriptor instead of
> >"org.jdom.Element".
> >
> >Example:
> >
> >I want to use:
> >public static List tablesParser(Element tb1)
> >instead of
> >public static List tablesParser(org.jdom.Element tb1)
> >
> >
> >Thanks,
> >
> >Justin Wall
> >
> >_______________________________________________
> >To control your jdom-interest membership:
> >http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@you
> >rhost.com
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com




More information about the jdom-interest mailing list