Xpath Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • srinivasareddynr
    New Member
    • Jan 2008
    • 3

    #1

    Xpath Problem

    Hi, I am trying to parse an xml using xpath. I dont have any problem when i try it as a standalone java application, but when I try the same code with in a servlet I am getting the below error. Can any one help me please. I need a solution ASAP.

    SRVE0026E: [Servlet Error]-[javax/xml/xpath/XPathFactory]: java.lang.NoCla ssDefFoundError : javax/xml/xpath/XPathFactory
    at com.ibm.cod.eve nt.hitsReport.p rocess(hitsRepo rt.java(Compile d Code))
    at com.ibm.cod.con troller.servlet .GenerateHitExc el.process(Gene rateHitExcel.ja va:82)
    at com.ibm.cod.con troller.servlet .GenerateHitExc el.doPost(Gener ateHitExcel.jav a:32)
    at com.ibm.cod.con troller.servlet .GenerateHitExc el.doGet(Genera teHitExcel.java :27)
    at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:740)
    at javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:853)
    at com.ibm.ws.webc ontainer.servle t.StrictServlet Instance.doServ ice(StrictServl etInstance.java :110)
    at com.ibm.ws.webc ontainer.servle t.StrictLifecyc leServlet._serv ice(StrictLifec ycleServlet.jav a:174)
    at com.ibm.ws.webc ontainer.servle t.IdleServletSt ate.service(Str ictLifecycleSer vlet.java:313)
    at com.ibm.ws.webc ontainer.servle t.StrictLifecyc leServlet.servi ce(StrictLifecy cleServlet.java :116)
    at com.ibm.ws.webc ontainer.servle t.ServletInstan ce.service(Serv letInstance.jav a:283)
    at com.ibm.ws.webc ontainer.servle t.ValidServletR eferenceState.d ispatch(ValidSe rvletReferenceS tate.java:42)
    at com.ibm.ws.webc ontainer.servle t.ServletInstan ceReference.dis patch(ServletIn stanceReference .java:40)
    at com.ibm.ws.webc ontainer.webapp .WebAppRequestD ispatcher.handl eWebAppDispatch (WebAppRequestD ispatcher.java: 948)
    at com.ibm.ws.webc ontainer.webapp .WebAppRequestD ispatcher.dispa tch(WebAppReque stDispatcher.ja va:530)
    at com.ibm.ws.webc ontainer.webapp .WebAppRequestD ispatcher.forwa rd(WebAppReques tDispatcher.jav a:176)
    at com.ibm.ws.webc ontainer.srt.We bAppInvoker.doF orward(WebAppIn voker.java:79)
    at com.ibm.ws.webc ontainer.srt.We bAppInvoker.han dleInvocationHo ok(WebAppInvoke r.java:201)
    at com.ibm.ws.webc ontainer.cache. invocation.Cach edInvocation.ha ndleInvocation( CachedInvocatio n.java:71)
    at com.ibm.ws.webc ontainer.cache. invocation.Cach eableInvocation Context.invoke( CacheableInvoca tionContext.jav a:114)
    at com.ibm.ws.webc ontainer.srp.Se rvletRequestPro cessor.dispatch ByURI(ServletRe questProcessor. java:186)
    at com.ibm.ws.webc ontainer.oselis tener.OSEListen erDispatcher.se rvice(OSEListen er.java:334)
    at com.ibm.ws.webc ontainer.http.H ttpConnection.h andleRequest(Ht tpConnection.ja va:56)
    at com.ibm.ws.http .HttpConnection .readAndHandleR equest(HttpConn ection.java:610 )
    at com.ibm.ws.http .HttpConnection .run(HttpConnec tion.java:431)
    at com.ibm.ws.util .ThreadPool$Wor ker.run(ThreadP ool.java(Compil ed Code))



    Thanks in advance...
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by srinivasareddyn r
    Hi, I am trying to parse an xml using xpath. I dont have any problem when i try it as a standalone java application...
    Thanks in advance...
    Hello, srinivasareddyn r!

    Are you able to go through the code in debug mode, if so, can you point out the line the occurs?

    Sorry for your troubles by the way...

    Dököll
    Last edited by Dököll; Jan 5 '08, 02:50 AM. Reason: deleted text...

    Comment

    • srinivasareddynr
      New Member
      • Jan 2008
      • 3

      #3
      Hi,

      Thanks for the reply and below is the code I am using.....

      DocumentBuilder Factory domFactory = DocumentBuilder Factory.newInst ance();
      domFactory.setN amespaceAware(t rue); // never forget this!
      DocumentBuilder builder = domFactory.newD ocumentBuilder( );
      Document doc = builder.parse(A dvisorXmlPath);
      System.out.prin tln(doc.getElem entsByTagName(" rec").getLength ());
      XPathFactory factory = XPathFactory.ne wInstance();
      XPath xpath = factory.newXPat h();
      String expr = "English/rec[@id='" + rs1.getInt("hit _id") + "']";
      Object result = xpath.evaluate( expr, doc, XPathConstants. NODE);
      Node nodes = (Node) result;
      hit_name = nodes.getAttrib utes().getNamed Item("name").ge tNodeValue();

      And when i try to run this code, it stopes at....

      XPathFactory factory = XPathFactory.ne wInstance();
      Can you please help me solve the problem... Thanks....




      Originally posted by Dököll
      Hello, srinivasareddyn r!

      Are you able to go through the code in debug mode, if so, can you point out the line the occurs?

      Sorry for your troubles by the way...

      Dököll

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by srinivasareddyn r
        Hi,

        Thanks for the reply and below is the code I am using.....

        DocumentBuilder Factory domFactory = DocumentBuilder Factory.newInst ance();
        domFactory.setN amespaceAware(t rue); // never forget this!
        DocumentBuilder builder = domFactory.newD ocumentBuilder( );
        Document doc = builder.parse(A dvisorXmlPath);
        System.out.prin tln(doc.getElem entsByTagName(" rec").getLength ());
        XPathFactory factory = XPathFactory.ne wInstance();
        XPath xpath = factory.newXPat h();
        String expr = "English/rec[@id='" + rs1.getInt("hit _id") + "']";
        Object result = xpath.evaluate( expr, doc, XPathConstants. NODE);
        Node nodes = (Node) result;
        hit_name = nodes.getAttrib utes().getNamed Item("name").ge tNodeValue();

        And when i try to run this code, it stopes at....

        XPathFactory factory = XPathFactory.ne wInstance();
        Can you please help me solve the problem... Thanks....
        NoClassDef is a missing class issue. Either you do not have the package that contains the javax/xml/xpath/XPathFactory class or it's not added to the project's classpath.

        Comment

        • srinivasareddynr
          New Member
          • Jan 2008
          • 3

          #5
          Thanks for the reply, but i have a different problem here.... when I try the same code in a standalone java application it is working but when I use the same code in a servlet is throws the above error.... Thanks....

          Originally posted by r035198x
          NoClassDef is a missing class issue. Either you do not have the package that contains the javax/xml/xpath/XPathFactory class or it's not added to the project's classpath.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by srinivasareddyn r
            Thanks for the reply, but i have a different problem here.... when I try the same code in a standalone java application it is working but when I use the same code in a servlet is throws the above error.... Thanks....
            You don't have a different problem: if your stand alone application can run that
            class it means that the jvm can find the class. The jvm that runs your servlet
            can't find that class so you should fix that, i.e. stick the corresponding jar where
            it belongs in the context of the jvm that runs your servlets. IOW, it's a class and/or
            classpath problem just as the other poster pointed out.

            kind regards,

            Jos

            Comment

            Working...