Solved

java.net.MalformedURLException: no protocol for entity in XML

Posted on 2007-12-04
5
4,551 Views
Last Modified: 2013-11-23
Hello,
I have a Java program that transform XML files to another format using Saxon 8.7. It works fine for a single full XML file. When I try to transform a XML with entity file references, I got the no protocol error.
 
The XML looks like this:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE document PUBLIC "-//My Document DTD v1.1 20030520//EN" "mydtd/project.dtd" [
      <!ENTITY file_01 SYSTEM "file_01.xml">
      <!ENTITY file_02 SYSTEM "file_02.xml">
      <!ENTITY file_03 SYSTEM "file_03.xml">
      <!ENTITY file_04 SYSTEM "file_04.xml">
]>
<document xmlns:xlink="http://www.w3.org/1999/xlink">
      <title>Title here</title>
&file_01;
&file_02;
&file_03;
&file_04;
</document>

The error is:
net.sf.saxon.trans.DynamicError: java.net.MalformedURLException: no protocol: file_01.xml

I have catalog file to map my DTD so those are working fine. But as for the entity files, each project has different file so I don't think I map each of them.

Is there any solution in transforming this without getting the protocol error? Thank you for any help.

Owon. S.
0
Comment
Question by:owonseed
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:R7AF
ID: 20411118
Can you explain a bit more what you're trying to do? Are you using XSLT to transform the XML into another format?

Is it correct that your code includes those file_xx.xml documents into one big XML file? How does that work and does it mean the declaration is included as well? Is the resulting XML well formed?
0
 

Author Comment

by:owonseed
ID: 20413392
Yes, I'm using XSLT (Saxon 8.7) to transform the XML to HTML format. Instead of one big XML file, my main XML contains only the external entity references to the smaller files (file_xx.xml). Main reason is the smaller files are created separately, so we only use external entity for those to keep thing simple.

Both of the main and smaller XML files are valid. When I put them together into one big file, it validates without any problem. In fact I can transformed it fine.

I can transform the main + external entity xml fine ** if ** I run it on local Windows desktop. The DTD is valid as well as a separate project.dtd file.

The problem only appears when it is using external entity, on the server. I have a java program that does the transform.

In my main xml, I can't use file:///file_xx.xml because I can't validate it properly using XML editor. In Windows it tries to find it in C:\file_xx.xml.  Nor can I use the full path to the file (file:///C:/myfolder/xslt/project_1/file_xx.xml. Because the path will not be valid after I put the file to the server. So relative path is the only way to go I believe. But this became a problem where the XSLT processor couldn't find the file_xx.xml because there is no protocol defined.

Using the external entity is the requirement so I can't put the content together as one big xml file.

O.S
0
 
LVL 13

Expert Comment

by:R7AF
ID: 20414170
You can use the document() function in XSLT to read multiple XML documents. This example assumes the file_xx.xml files are in the same folder as the xml and xslt. That is easiest to start with, but you can move them around like you do with HTML, using relative paths etc.

http://www.xml.com/pub/a/2002/03/06/xslt.html
<!-- index.xml -->
 
<?xml version="1.0" encoding="utf-8"?>
 
<document xmlns:xlink="http://www.w3.org/1999/xlink">
   <title>Title here</title>
   <files>
      <file>file_01.xml</file>
      <file>file_02.xml</file>
      <file>file_03.xml</file>
      <file>file_04.xml</file>
   </files>
</document>
 
<!-- file_01.xml -->
 
<?xml version="1.0" encoding="UTF-8"?>
<test>
	<id>345</id>
</test>
 
<!-- test.xsl -->
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:template match="files">
		<xsl:apply-templates select="file"/>
	</xsl:template>
	
	<xsl:template match="file">
		<xsl:apply-templates select="document(.)/path/to/node"/>
	</xsl:template>
</xsl:stylesheet>

Open in new window

0
 
LVL 13

Accepted Solution

by:
R7AF earned 250 total points
ID: 20414182
Sorry, test.xsl should be:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:template match="files">
		<xsl:apply-templates select="file"/>
	</xsl:template>
	
	<xsl:template match="file">
		<xsl:apply-templates select="document(.)/test/id"/>
	</xsl:template>
</xsl:stylesheet>

Open in new window

0
 

Author Comment

by:owonseed
ID: 20459608
Thanks for the suggestion. Unfortunately the file format and the external entity references must remain unchanged. I'll try to implement your solution on my program but the files were created from a conversion process that I can't change. Part of the requirment is that I shouldn't change any of the source either. That's a bummer. Seems like I have no control over the file format. Therefore I need to find another way to deal with the external entity.
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat startup error 5 102
ejb wildfly example 2 20
pagenation logic how it is working in my code 1 53
servlet and mdb, jms error 1 32
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video teaches viewers about errors in exception handling.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question