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!

Entity include with relative path in XML using JAXB

843834Apr 30 2007 — edited Apr 30 2007
Moving this from the Java Technologies for Web Services forum to this one.

With the jwsdp jars I'm trying to use JAXB to load in several specified XML files. This works fine. The XML files are read in from a relative link "/templates/mainXML.xml" and the xml string read in and passed to the unmarshaller as a StreamSource:

BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResource(xmlPath_).openStream()));
while ( (line = reader.readLine()) != null) {
buff.append(line.trim()+"\n");
}
String xml = buff.toString();
u.unmarshall(new StreamSource(new StringReader(xml)))

But my XML files are becoming rather large with some repitition across the files so I'd like to use the entity incude in the header of the XML to abstract some of the XML into addMe.xml e.g:

<!DOCTYPE StrategyTemplate [
<!ENTITY IncludeTimeComponent SYSTEM "file:///templates/addMe.xml">
]>

with &IncludeTimeComponent;

But it gives this error:

Caused by: java.io.FileNotFoundException: \templates\addMe.xml (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
at java.net.URL.openStream(URL.java:1007)
at weblogic.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:836)
at weblogic.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:767)
at weblogic.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEntityReference(XMLDocumentFragmentScannerImpl.java:1095)
at weblogic.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1513)
at weblogic.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:329)
at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:525)
at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:581)
at weblogic.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
at weblogic.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1175)
at weblogic.xml.jaxp.WebLogicXMLReader.parse(WebLogicXMLReader.java:135)
at weblogic.xml.jaxp.RegistryXMLReader.parse(RegistryXMLReader.java:152)
at com.lb.cmte.oms.interpreter.jaxb.impl.runtime.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:140)
... 11 more

It works fine if I put the file in the working directory or supply the full path e.g.

<!DOCTYPE StrategyTemplate [
<!ENTITY IncludeTimeComponent SYSTEM "file:///C:/dev/templates/addMe.xml">
]>

with &IncludeTimeComponent;

I've tried using jwsdp2.0 jars rather than 1.4 I was using previously, but with the same result.

But I don't want to do that, because I don't know where that might be. I'd like to be able to supply the xml file's path as it would be shown within a JAR as I do currently for the mainXML.xml files. Thanks in advance for any help!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 28 2007
Added on Apr 30 2007
3 comments
1,701 views