File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Read and parse Flatpack xml file in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Read and parse Flatpack xml file in java" Watch "Read and parse Flatpack xml file in java" New topic

Read and parse Flatpack xml file in java

Madhavi Subramaniam
Ranch Hand

Joined: Nov 24, 2011
Posts: 33

I've flatpack xml file in one jar that located in war lib as following

<?xml version="1.0"?>
<!-- DTD can be pulled from the Jar or over the web-->
<!DOCTYPE PZMAP SYSTEM "flatpack.dtd" >
<COLUMN name="CITY" />
<COLUMN name="STATE" />
<COLUMN name="ZIP" />


I read this file like

inputstream = getClass().getResourceAsStream(filename);

but i'm gettig 'File not found exception' like jbosslocation/bin/flatpack.dtd is not found

i kept my xml file in war lib and gave the correct location..but i don't know why it searching in jboss bin folder.

can anyone figure out my mistake and suggest the solution.

Madhavi Subramaniam
Ranch Hand

Joined: Nov 24, 2011
Posts: 33
Myself found the answer for this problem

InputStream inputstream = null;
XMLInputFactory factory = XMLInputFactory.newInstance();

factory.setProperty("", false);
factory.setProperty("", false);
inputstream = getClass().getResourceAsStream(filename);
XMLStreamReader streamReader = factory.createXMLStreamReader(inputstream);
Stax2DomBuilder builder = new Stax2DomBuilder();
Document document =;
NodeList fieldDetails = document.getElementsByTagName("COLUMN");


John Jai

Joined: May 31, 2011
Posts: 1776
So the solution is to mark the program not to check the DTD file marked by the SYSTEM doctype?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

This line:

says (among other things) that the URL to find the "flatpack.dtd" document is the same as the URL for the XML document it's contained in except that the file part is "flatpack.dtd". In other words the two are in the same folder.

However this is only useful if the parser actually knows the URL of the XML document. In this case since you passed in an InputStream it has no idea of the URL where it came from. If you had used the getResource() method instead of getResourceAsStream(), and passed the resulting URL to the parser, then it would have known where to look for the DTD.
I agree. Here's the link:
subject: Read and parse Flatpack xml file in java
It's not a secret anymore!