Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4956
  • Last Modified:

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

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
owonseed
Asked:
owonseed
  • 3
  • 2
1 Solution
 
R7AFCommented:
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
 
owonseedAuthor Commented:
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
 
R7AFCommented:
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
 
R7AFCommented:
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
 
owonseedAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now