Solved

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

Posted on 2007-12-04
5
4,481 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now