blue-genie
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.
Anyone have any ideas why?
ta
blu.
Probably not reading the file correctly. How are you reading it?
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.
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.
in terms of how we are reading it -
documentbuilderfactory
javac.xml.parsers.*
reading it by gettting elements and nodes.
ASKER
here's the method...
DocumentBuilderFactory dbf = DocumentBuilderFactory.new Instance() ;
try {
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(coursePath);
Element docEle = dom.getDocumentElement();
NodeList nl = docEle.getElementsByTagNam e("lom:gen eral");
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).getChildN odes();
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("parseM anifestFil e() " + 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 -SCORM2004 ExamplePkg " 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:strin g>
</lom:keyword>
<lom:keyword>
<lom:string language="en-US">keyword2< /lom:strin g>
</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.
DocumentBuilderFactory dbf = DocumentBuilderFactory.new
try {
DocumentBuilder db = dbf.newDocumentBuilder();
Document dom = db.parse(coursePath);
Element docEle = dom.getDocumentElement();
NodeList nl = docEle.getElementsByTagNam
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).getChildN
for (int y = 0; y < innerChildren.getLength();
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("parseM
}
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
<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:keyword>
<lom:keyword>
<lom:string language="en-US">keyword2<
</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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
CEHJ - we get a malformed url exception
any idea?
any idea?
ASKER
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
CEHJ - we get a malformed url exception
any idea?
>>
Please post stack trace
ASKER
java.net.MalformedURLExcep
at java.net.URL.<init>(URL.ja
at java.net.URL.<init>(URL.ja
at java.net.URL.<init>(URL.ja
at com.sun.org.apache.xerces.
at com.sun.org.apache.xerces.
at com.sun.org.apache.xerces.
at com.sun.org.apache.xerces.
at com.sun.org.apache.xerces.
at com.sun.org.apache.xerces.
at
at com.sun.org.apache.xerces.
at ManifestCourseReader.parse
at ManifestCourseReader.<init
at ManifestCourseReader.main(
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
thanks so long for your efforts objects.
ASKER
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.
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.
:-)