• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JSP and XML - Need your help

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a static xml and an xsl file and a jsp file , my task is
JSP file takes the XML file and the XSL file and outputs plain HTML to the browser.I'm using xerces parser.Can any body helpme out to solve this problem.
Moreover I tried a the following sample program....
When I run this it says NoClassDefFoundError , I hope the classpath are set right.
----------------------------------------------------------------
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.io.IOException;
// A Simple DOM Application
public class BasicDOM {

// Constructor
public BasicDOM (String xmlFile) {

// Create a Xerces DOM Parser
DOMParser parser = new DOMParser();
// Parse the Document
// and traverse the DOM
try {
parser.parse(xmlFile);
Document document = parser.getDocument();
traverse (document);
} catch (SAXException e) {
System.err.println (e);
} catch (IOException e) {
System.err.println (e);
}
}

// Traverse DOM Tree. Print out Element Names
private void traverse (Node node) {
int type = node.getNodeType();
if (type == Node.ELEMENT_NODE)
System.out.println (node.getNodeName());
NodeList children = node.getChildNodes();
if (children != null) {
for (int i=0; i< children.getLength(); i++)
traverse (children.item(i));
}
}

// Main Method
public static void main (String[] args) {
BasicDOM basicDOM = new BasicDOM (args[0]);
}
}
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure the parser jar files are in your classpath. The best way to test this is to copy the example programs that came with the Xerces download to your client directory and try to run it. If you're able to run the sample programs, you're fine. Otherwise you will need to fix the classpath first.
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
your program working fins in my system. may be class path for xerces.jar file is not set properly. For DOMParser you need to import org.apache.xerces.parsers package. and try it, it is working fine.
bye
glkishore
 
Are you okay? You look a little big. Maybe this tiny ad will help:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic