• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Converting a string to DOM

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to convert a string into a DOMDocument. As far as I can tell, the string is valid XML. Here's the relevant block of code:

It dies on the SAXReader line, although it isn't throwing a SAXException. Instead I get java.lang.ClassNotFoundException: plus the entire string I am trying to convert.

Any ideas on what I am doing wrong?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be most useful to see the actual exception, particularly the name of the class that is not found.
 
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SAXReader isn't in the standard Java API. I guess from my Google search you're asking about the class in DOM4J? What I found didn't have any documentation for this constructorbut the name of the parameter does suggest you should be passing it a class name and not a String containing XML.

Okay, that's what you're doing wrong. How should you do it right? Based on the documentation I saw, I would try something likebut that's just a guess. If it were me I would be looking around the DOM4J documentation for some example code.
 
Andrew McLaren
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ulf Dittmer:
It would be most useful to see the actual exception, particularly the name of the class that is not found.



That's one of the (many!) things that's confusing me here. After the ClassNotFoundException, it gives returns the contents of the string I am passing into SAXReader, implying to me that it is looking for a class named the contents of the string.
But according to the JavaDocs for dom4j, that's a valid constructor.
 
Andrew McLaren
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
SAXReader isn't in the standard Java API. I guess from my Google search you're asking about the class in DOM4J? What I found didn't have any documentation for this constructorbut the name of the parameter does suggest you should be passing it a class name and not a String containing XML.

Okay, that's what you're doing wrong. How should you do it right? Based on the documentation I saw, I would try something likebut that's just a guess. If it were me I would be looking around the DOM4J documentation for some example code.



Aha! That gets me farther, at least. Now it's complaining about the markup not being well formed, but that I think I can handle.

Thanks much!

Andrew
 
reply
    Bookmark Topic Watch Topic
  • New Topic