Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to ignore white space when parse xml document using xerces 2.4.0

843834Jun 26 2003 — edited Jun 27 2003
When I run the program with the xml given below the following error comes.

Problem parsing the file.java.lang.NullPointerExceptionjava.lang.NullPointerExce
ption
at SchemaTest.main(SchemaTest.java:25)

============================================================
My expectation is "RECEIPT". Pls send me the solution.

import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.InputSource;
import java.io.*;
import org.xml.sax.ErrorHandler;
import org.w3c.dom.*;
public class SchemaTest {
public static void main (String args[])
{


try
{

FileInputStream is = new FileInputStream(new File("C:\\ADL\\imsmanifest.xml"));
InputSource in = new InputSource(is);
DOMParser parser = new DOMParser();
//parser.setFeature("http://xml.org/sax/features/validation", false);
//parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", "memory.xsd");
//ErrorHandler errors = new ErrorHandler();
//parser.setErrorHandler(errors);
parser.parse(in);
Document manifest = parser.getDocument();
manifest.normalize();
NodeList nl = manifest.getElementsByTagName("organization");
System.out.println((((nl.item(0)).getChildNodes()).item(0)).getFirstChild().getNodeValue());
}
catch (Exception e)
{
System.out.print("Problem parsing the file."+e.toString());
e.printStackTrace();
}
}
}


<?xml version = '1.0'?>
<organizations default="detail">
<organization identifier="detail" isvisible="true">
<title>RECEIPT</title>
<item identifier="S100000" identifierref="R100000" isvisible="true">
<title>Basic Module</title>
<item identifier="S100001" identifierref="R100001" isvisible="true">
<title>Objectives</title>
<metadata/>
</item>
</item>

<metadata/>
</organization>
</organizations>


Is there a white space problem? How do I get rid from this problem.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 25 2003
Added on Jun 26 2003
5 comments
312 views