[jdom-interest] exception all over the place !!
ShantAdam
adams at multispex.com
Sat Mar 16 10:04:09 PST 2002
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?
[code]
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import org.jdom.Attribute;
import org.jdom.Comments;
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, JDOMExcption {
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")
.addAttribute(new Attribute("dist", "RedHat 6.1"))
.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®
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20020316/a89763bf/attachment.htm
More information about the jdom-interest
mailing list