Link to home
Start Free TrialLog in
Avatar of blue-genie
blue-genieFlag for South Africa

asked on

xml parser + java/jsp question

i have a class that reads an xml file, manage to parse and return values correctly when compile and run in console, however, when running the class from the jsp file - it's all returning nulls.
Anyone have any ideas why?

ta
blu.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Probably not reading the file correctly. How are you reading it?
Avatar of runa_paathak
runa_paathak

If it is returning correct values when you run it from console, but not as part of an application (jsp page), I think it could be a problem related to file paths. Just check if you are giving the right path to the xml file in your jsp.
Avatar of blue-genie

ASKER

we're quite sure its finding the file, we did a if (fileExists) - which returns true

in terms of how we are reading it -
documentbuilderfactory
javac.xml.parsers.*
reading it by gettting elements and nodes.
here's the method...


DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      

try {
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(coursePath);
                  
                  
Element docEle = dom.getDocumentElement();
NodeList nl = docEle.getElementsByTagName("lom:general");
                  
if (nl != null && nl.getLength() > 0) {
                  
      for (int i = 0; i < nl.getLength(); i++) {
                        
            Element el = (Element) nl.item(i);
                      NodeList children = el.getChildNodes();

      for (int x = 0; x < children.getLength(); x++) {
                                    
      NodeList innerChildren = children.item(x).getChildNodes();
      for (int y = 0; y < innerChildren.getLength(); y++) {
                                    
      String value = innerChildren.item(y)+"";
                                    
      //over here value is null when called from the jsp but contains the values I want when run from the console      }
      }
      }
      }
            } catch (Exception e) {
                  System.out.println("parseManifestFile() " + e);
            }



here's a bit of the xml...


<?xml version="1.0" encoding="UTF-8"?>
<!--This is a Reload version 1.3.2 Beta2_c SCORM 2004 Content Package document-->
<!--Spawned from the Reload Content Package Generator - http://www.reload.ac.uk-->
<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1" xmlns:lom="http://ltsc.ieee.org/xsd/LOM" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:adlcp="http://www.adlnet.org/xsd/adlcp_v1p3" xmlns:imsss="http://www.imsglobal.org/xsd/imsss" xmlns:adlseq="http://www.adlnet.org/xsd/adlseq_v1p3" xmlns:adlnav="http://www.adlnet.org/xsd/adlnav_v1p3" identifier="MANIFEST-AADLC-SCORM2004ExamplePkg" xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd http://ltsc.ieee.org/xsd/LOM lom.xsd http://www.adlnet.org/xsd/adlcp_v1p3 adlcp_v1p3.xsd http://www.imsglobal.org/xsd/imsss imsss_v1p0.xsd http://www.adlnet.org/xsd/adlseq_v1p3 adlseq_v1p3.xsd http://www.adlnet.org/xsd/adlnav_v1p3 adlnav_v1p3.xsd" version="1.3">
  <metadata>
    <schema>ADL SCORM</schema>
    <schemaversion>CAM 1.3</schemaversion>
      <lom:lom>
            <lom:general>
                  <lom:title>
                        <lom:string language="en-US">Title for the Package</lom:string>
                        <lom:string language="hebrew">kus emak!</lom:string>
                  </lom:title>
                  <lom:description>
                        <lom:string language="en-US">Textual Description</lom:string>
                  </lom:description>
                  <lom:keyword>
                        <lom:string language="en-US">keyword1</lom:string>
                  </lom:keyword>
                  <lom:keyword>
                        <lom:string language="en-US">keyword2</lom:string>
                  </lom:keyword>
                  <lom:coverage>
                        <lom:string language="en-US">this is my coverage</lom:string>
                  </lom:coverage>
                  <lom:structure>
                        <lom:string language="en-US">this is my structure</lom:string>
                  </lom:structure>
                  <lom:aggregationLevel>
                        <lom:string language="en-US">this is my aggregation</lom:string>
                  </lom:aggregationLevel>
            </lom:general>
      </lom:lom>


we're trying to get the stuff between the general nodes.

ta peeps.
SOLUTION
Avatar of mukundha_expert
mukundha_expert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
wer're using absolute paths. ie. c:\ and we've run checks in the jsp to see that its pointing to the right file.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
CEHJ  - we get a malformed url exception
any idea?
cehj, since we're using absolute paths, we know the file can be found, otherwise it would be throwing a fileNOt found exception? yea?
>>
 CEHJ  - we get a malformed url exception
any idea?
>>

Please post stack trace

java.net.MalformedURLException
        at java.net.URL.<init>(URL.java:601)
        at java.net.URL.<init>(URL.java:464)
        at java.net.URL.<init>(URL.java:413)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:968)
        at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:184)
 

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:798)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)

        at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:250)
        at

at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:292)
        at ManifestCourseReader.parseManifestFile(ManifestCourseReader.java:120)
        at ManifestCourseReader.<init>(ManifestCourseReader.java:53)
        at ManifestCourseReader.main(ManifestCourseReader.java:313)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi, the guy who's working with me on this is off on study leave for a while, when he gets back i'll have him take a look, i haven't abandoned the issue :-)
thanks so long for your efforts objects.
ok, objects that didn't help.
but he's used a different xml parser now instead of the ADL one and he seems to have solved it.
so for ur efforts, though this hasn't been resolved i'm gonna split the points and assign a B.
thanks ppl.
:-)