[jdom-interest] Re: jdom 1.0 XMLOutputter -- problems

Frances fdr58 at yahoo.com
Wed May 10 14:35:49 PDT 2006


thank you..  where is code that actually creates xml file..  for example 
if I want to put elements created here in a file called myinfo.xml, how 
would I do that..

I see various packages that come w/jdom download, however can find only 
docs for jdom.jar, where are docs for all other jars in this download 
(xalan.jar, xerces.jar, xml-apis.jar, etc... I have never been able to 
find docs for xml-apis.jar, it comes also with Tomcat, why no docs..) 
thanks..



Edelson, Justin wrote:
> Here's some basic document creation code:
> 	Document document = new Document();
> 	Element rootElement = new Element("root");
> 	document.setRootElement(rootElement);
> 	Element childElement = new Element("child");
> 	rootElement.addContent(childElement);
> 	childElement.setText("some text"); 
> 
> Same code all on one line:
> 	Document doc2 = new Document().setRootElement(new
> Element("root").addContent(new Element("child").setText("some text")));
> 
> As for your other issues, these really don't have anything to do with
> jdom. I suggest you read up on the importance of the classpath to figure
> out why your are getting a ClassNotFoundException. Comparing
> command-line Java with Tomcat isn't really a valid comparison as Tomcat
> is a container that uses custom classloaders based on a directory
> structure.
> 
> As for your FileNotFoundException, any reason to think this isn't just
> because this file doesn't exist?
> 
> Justin
> 
> -----Original Message-----
> From: jdom-interest-bounces at jdom.org
> [mailto:jdom-interest-bounces at jdom.org] On Behalf Of Frances
> Sent: Monday, April 03, 2006 4:52 PM
> To: jdom-interest at jdom.org
> Subject: [jdom-interest] Re: jdom 1.0 XMLOutputter -- problems
> 
> Bradley S. Huffman wrote:
> 
>>>Exception in thread "main" java.lang.NoClassDefFoundError: 
>>>org/jdom/input/SAXBuilder..
>>>
>>>I downloaded jdom this weekend, put jdom.jar and all other jars that 
>>>come with the download in the classpath...  but get many errors when 
>>>trying to compile stuff (deprecated methods (like addAttribute(), 
>>>which I change to setAttribute() but still get errors..  errors that 
>>>SAXBuilder and XMLOutputter can't be found.. I looked in jar, I looked
> 
> 
>>>in docs, these classes are there..) what is the problem pls, thank
> 
> you...
> 
>>
>>addAttribute?  Sounds like there's a very old jar in your classpath. 
>>Did you download from http://www.jdom.org/dist/binary either 
>>jdom-1.0.tar.gz or jdom-1.0.zip, and are you sure it's in your
> 
> classpath?
> 
>>Brad
>>_______________________________________________
>>To control your jdom-interest membership:
>>http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.co
>>m
>>
> 
> yes and yes....
> 
> downloaded just this weekend, downloaded jdom-1.0.zip...
> 
> ok, look at this small example, from
> http://www.javaworld.com/javaworld/jw-05-2000/jw-0518-jdom-p2.html
> 
> import java.io.*;
> import org.jdom.*;
> import org.jdom.input.SAXBuilder;
> import org.jdom.input.*;
> import org.jdom.output.*;
> 
> public class PrettyPrinter {
>     public static void main(String[] args) {
>      //    Assume filename argument
>      //    String filename = args[0];
> 	  String filename = "myFile";
> 
>          try {
>              // Build the document with SAX and Xerces, no validation
>              SAXBuilder builder = new SAXBuilder();
>              // Create the document
>              Document doc = builder.build(new File(filename));
> 
>              // Output the document, use standard formatter
>              XMLOutputter fmt = new XMLOutputter();
>              fmt.output(doc, System.out);
>          } catch (Exception e) {
>              e.printStackTrace();
>          }
>      }
> }
> 
> this compiles fine but when run it with just this command:
> 
>      java PrettyPrinter
> 
> get following error: Exception in thread "main" 
> java.lang.NoClassDefFoundError: org/jdom/input/SAXBui lder (I don't get
> this.. if this class cannot be found how come it compiled fine?  do you
> need to always indicate cp when running classes with third-party API's?
> I don't have to do this w/Tomcat..)
> 
> if I run it like this:  java -cp jdom.jar;. PrettyPrinter
> 
> get this error:
> 
> java.io.FileNotFoundException: C:\Documents and Settings\fdelrio\My
> Documents\xslt\myFile (The system cannot find the file specified)
>          at java.io.FileInputStream.open(Native Method)
>          at java.io.FileInputStream.<init>(Unknown Source)
>          at java.io.FileInputStream.<init>(Unknown Source)
>          at sun.net.www.protocol.file.FileURLConnection.connect(Unknown
> Source)
>          at
> sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown So
> urce)
>          at java.net.URL.openStream(Unknown Source)
>          at org.apache.crimson.parser.InputEntity.init(Unknown Source)
>          at org.apache.crimson.parser.Parser2.parseInternal(Unknown
> Source)
>          at org.apache.crimson.parser.Parser2.parse(Unknown Source)
>          at org.apache.crimson.parser.XMLReaderImpl.parse(Unknown
> Source)
>          at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
>          at org.jdom.input.SAXBuilder.build(SAXBuilder.java:810)
>          at org.jdom.input.SAXBuilder.build(SAXBuilder.java:789)
>          at PrettyPrinter.main(PrettyPrinter.java:20)
> 
> 
> I would LOVE to have some code to just create a simple xml file with
> JDOM.. (still don't know if SAX or DOM is best...)  'parsing' means to
> READ an xml file, so if you're CREATING an xml file you don't need to
> parse right?  sorry if these questions sound stupid, am just beginning
> to learn all this stuff.. finally know diff betw. SAX and DOM... :)
> 
> thank you very much..
> 
> Frances
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> 



More information about the jdom-interest mailing list