[jdom-interest] exception all over the place !!

ShantAdam adams at multispex.com
Sun Mar 17 16:20:00 PST 2002


Alright;

Here's the deal I just updated my JDOM 8b and JDK1.4.
it seems like I may be a bit slow on updating programs.

So, I get these errors:

C:\WINDOWS\Desktop\jdomTest>javac -deprecation JDOMTest.java
JDOMTest.java:24: cannot resolve symbol
symbol  : method addProcessingInstruction
(java.lang.String,java.lang.String)
location: class org.jdom.Document
                Document doc = new Document (new Element("config", ns))
                               ^
JDOMTest.java:41: setContent(java.util.List) in org.jdom.Element cannot be
applied to (java.lang.String)
                                        .addChild(new Element("name")
                                                  ^
JDOMTest.java:38: cannot resolve symbol
symbol  : method addChild  (org.jdom.Comment)
location: class org.jdom.Element
                        .addChild(new Element("sound")
                                  ^
JDOMTest.java:35: setContent(java.util.List) in org.jdom.Element cannot be
applied to (java.lang.String)
                        .addAttribute(new Element("gui", ns)
                                      ^
JDOMTest.java:31: cannot resolve symbol
symbol  : method addAttribute  (java.lang.String,java.lang.String)
location: class org.jdom.Element
                doc.getRootElement()
                                  ^
JDOMTest.java:53: warning: build(java.io.File) in org.jdom.input.DOMBuilder
has been deprecated
                Document doc = builder.build(file);
                                      ^
JDOMTest.java:101: cannot resolve symbol
symbol  : method getRootCause  ()
location: class org.jdom.JDOMException

System.out.println(((JDOMException)e).getRootCause()
                                                   ^
6 errors
1 warning

And Here's the corrected version of my code:

[code]
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;

import org.jdom.Attribute;
import org.jdom.Comment;
import org.jdom.DocType;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.ProcessingInstruction;
import org.jdom.input.DOMBuilder;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;

public class JDOMTest{
 public JDOMTest(){
 }

 public void newDocument(OutputStream out)
  throws IOException, JDOMException {
  Namespace ns = Namespace.getNamespace("linux","http://www.linux.org");
  Document doc = new Document (new Element("config", ns))
   .setDocType(new DocType("linux:config", "DTD/linux.dtd"))
   .addProcessingInstruction("cocoon-process",
           "type=\"xsp\"")
   .addProcessingInstruction(
    new ProcessingInstruction("cocoon-process",
            "type=\"xslt\""));
  doc.getRootElement()
   .addAttribute("Kernel", "2.2.14") //easy way
   .addAttribute(
    new Attribute("dist", "RedHat 6.1")) //hard way
   .addAttribute(new Element("gui", ns)
    .setContent("No Window Manager Installed"))
   .addChild(new Comment("Sound Card Configuration"))
   .addChild(new Element("sound")
    .addChild(new Comment("Sound Blaster Card"))
    .addChild(new Element("card")
     .addChild(new Element("name")
      .setContent("Sound Blaster Platinum")))
   );

  XMLOutputter fmt = new XMLOutputter();
  fmt.output(doc, out);
 }

 public void domDocument(File file, OutputStream out)
  throws IOException, JDOMException{

  DOMBuilder builder = new DOMBuilder(true);
  Document doc = builder.build(file);

  XMLOutputter fmt = new XMLOutputter();
  fmt.output(doc, out);
 }

 public void saxDocument(File file, OutputStream out)
  throws IOException, JDOMException{

  SAXBuilder builder = new SAXBuilder(true);
  Document doc = builder.build(file);

  XMLOutputter fmt = new XMLOutputter();
  fmt.output(doc, out);
 }

 public static void main(String[] args){
  if(args.length != 1){
   System.out.println("Usage: JDOMTest (filename to parse)");
   System.exit(-1);
  }

  try{
  JDOMTest test = new JDOMTest();
  System.out.println("\n\n----------------------------------------------");
  System.out.println("Testing creating Document from scratch ...");
  System.out.println("----------------------------------------------\n\n");

  test.newDocument(System.out);

  System.out.println("\n\n----------------------------------------------");
  System.out.println("Testing reading Document using DOM ...");
  System.out.println("----------------------------------------------\n\n");

  test.domDocument(new File(args[0]), System.out);

  System.out.println("\n\n----------------------------------------------");
  System.out.println("Testing reading Document using SAX ...");
  System.out.println("----------------------------------------------\n\n");

  test.saxDocument(new File(args[0]), System.out);

  System.out.println("\n\n----------------------------------------------");
  System.out.println("Tests complete. Successful build in place.");

  } catch (Exception e){
   e.printStackTrace();
   if(e instanceof JDOMException){
    System.out.println(((JDOMException)e).getRootCause()
        .getMessage());
   } else {
    System.out.println(e.getMessage());
   }
  }
 }
}
[/code]

Multispex Designs
Rep.: Shant Adam
Tel.: (514) 827-4840
adams at multispex.com
http://www.multispex.com
---
Visual technology service provider.
Fournisseur de service de technologie visuel.
---
Copyright 1998-2002©
Multispex Designs®

----- Original Message -----
From: "bob mcwhirter" <bob at werken.com>
To: "ShantAdam" <adams at multispex.com>
Cc: "jdom - interest" <jdom-interest at jdom.org>
Sent: Saturday, March 16, 2002 3:29 PM
Subject: Re: [jdom-interest] exception all over the place !!


>
> On Sat, 16 Mar 2002, ShantAdam wrote:
>
> > What about my code here.
> > It's giving me all sorts of errors on class and method; symbols not
beign resolved and so on.
> >
> > Can anyone tell where i'm wrong in this?
> >
> >  [ snip; a lot of code, no error messages ]
>
> <joke>
>   You forgot to pay Jason $10 to use JDOM...
> </joke>
>
> Truthfully though...
>
> 1) When having errors, let us know what they are.  Copy/paste is your
>    friend.
>
> 2) HTML email is evil.  Don't send it to mailing lists.
>
> 3) Tell us what you've already tried to do to solve your own problem.
>
>
> -bob
>
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
>
>




More information about the jdom-interest mailing list