This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
Author

Read and parse Flatpack xml file in java

Madhavi Subramaniam
Ranch Hand

Joined: Nov 24, 2011
Posts: 33
Hi,

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" >
<!--<!DOCTYPE PZMAP SYSTEM "http://flatpack.sourceforge.net/flatpack.dtd" >-->
<PZMAP>
<COLUMN name="FIRSTNAME" />
<COLUMN name="LASTNAME" />
<COLUMN name="ADDRESS" />
<COLUMN name="CITY" />
<COLUMN name="STATE" />
<COLUMN name="ZIP" />

</PZMAP>


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.

Thanks
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("javax.xml.stream.isReplacingEntityReferences", false);
factory.setProperty("javax.xml.stream.isSupportingExternalEntities", false);
inputstream = getClass().getResourceAsStream(filename);
XMLStreamReader streamReader = factory.createXMLStreamReader(inputstream);
Stax2DomBuilder builder = new Stax2DomBuilder();
Document document = builder.build(streamReader);
document.getDocumentElement().normalize();
NodeList fieldDetails = document.getElementsByTagName("COLUMN");

Thanks

John Jai
Bartender

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Read and parse Flatpack xml file in java
 
Similar Threads
WS and tomcat
classpath / external jars
new bee weblogic classloading
Unable to read html_basic.tld from jsf-impl-2.1.2.jar
libraries not found!