473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

XSLT: Relative URI "my.dtd" can not be resolved without a base URI

Greetings to all -

I'm having a problem processing xml with relative dtd URI specified
using XSLT:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mydoc SYSTEM "my.dtd">
<mydoc>
....
</mydoc>

I do not have a control over the original xml but I have my.dtd in the
app classpath. I'm getting the TransformerException: Relative URI
"my.dtd" can not be resolved without a base URI.

How do I tell to javax.xml.transform.Transformer where to find the dtd
file w/out specifying the base URI (or any other modifications of the
original xml)?

Here is how I call the xsl transformer:

// 1. Instantiate a TransformerFactory.
javax.xml.transform.TransformerFactory tFactory =
javax.xml.transform.TransformerFactory.newInstance ();

// 2. Use the TransformerFactory to process the stylesheet Source and
// generate a Transformer.
javax.xml.transform.Transformer transformer =
tFactory.newTransformer(new
javax.xml.transform.stream.StreamSource(xsl));

//transformer.setURIResolver(new RelativeURIResolver());

// 3. Use the Transformer to transform an XML Source and send the
// output to a Result object.
transformer.transform(
new javax.xml.transform.stream.StreamSource(xml),
new javax.xml.transform.stream.StreamResult(out));

As you can see above, I've tried to use URIResolver() but it does not
appear to be used by the transformer to resolve the DTD.

I'm using Java(TM) 2 Runtime Environment, Standard Edition (build
1.4.2_03-b02) and default xslt processor and xml parser from there
("org.apache.xalan.processor.TransformerFactoryImp l" and
"org.apache.crimson.jaxp.DocumentBuilderFactoryImp l" I assume).

Of course, I could use java.util.regex to either remove
<!DOCTYPE[a-zA-Z0-9\". ]*> completely or to add the base url there.
But I wonder if there is more elegant solution to this.

Any suggestions are very appreciated.
Thanks
Pavel
Jul 20 '05 #1
2 9365
"Pavel" <ol*********@comcast.net> wrote in message
news:e1**************************@posting.google.c om...
Greetings to all -

I'm having a problem processing xml with relative dtd URI specified
using XSLT:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mydoc SYSTEM "my.dtd">
<mydoc>
...
</mydoc>

I do not have a control over the original xml but I have my.dtd in the
app classpath. I'm getting the TransformerException: Relative URI
"my.dtd" can not be resolved without a base URI.

How do I tell to javax.xml.transform.Transformer where to find the dtd
file w/out specifying the base URI (or any other modifications of the
original xml)?

Hi Pavel,

Setting a custom URIResolver on the transformer won't help, since this URI
resolver is used only for resolving relative URI's passed to the XSLT
document function.

What you need to do instead is, on an XMLReader that is reading the XML
file, call the setEntityResolver method to set a custom EntityResolver.
Your custom EntityResolver needs to provide a resolveEntity method that will
do the job of substituting the absolute URL for the relative URL, see the
example of an EntityResolver in the java api docs.

So, instead of using a StreamSource to read the document, create an
XMLReader using an XMLReaderFactory, and set the EntityResolver to your
custom resolver, also create an InputSource object with the file URL, and
finally create a SAXSource object with the XMLReader and the InputSource.
That should do it.

Regards,
Daniel Parker
http://servingxml.sourceforge.net/
Jul 20 '05 #2
Pavel wrote:
Greetings to all -

I'm having a problem processing xml with relative dtd URI specified
using XSLT:

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mydoc SYSTEM "my.dtd">
<mydoc>
...
</mydoc>

I do not have a control over the original xml but I have my.dtd in the
app classpath. I'm getting the TransformerException: Relative URI
"my.dtd" can not be resolved without a base URI.

How do I tell to javax.xml.transform.Transformer where to find the dtd
file w/out specifying the base URI (or any other modifications of the
original xml)?


The default is usually to look for the DTD in the same place as the document
instance. If you can work out where Java thinks the document is coming from,
and put the DTD in the same place (directory/pipe/stream) then it should
find it.

///Peter
--
"The cat in the box is both a wave and a particle"
-- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Chris Krasnichuk | last post by:
hello, Does anyone know how I make php work on "my" computer? I made a mistake in my last post so I fixed it here. Chris
2
by: Genzo | last post by:
Hi all, was wondering if anyone might have knowledge on this. am testing with Opera 7.11. essentially whenever i try to use the substring "&lang=" in any string value in javascript, and try to...
4
by: timmy | last post by:
I have a table with a cell on the bottom right with an image to create a rounded corner effect: <table cellpadding="0" cellspacing="0" border="1"> <tr><td rowspan="2">asdfsadf</td> <td...
0
by: John Phelan | last post by:
It use to work. I created numerous coppies of my MS Access2003 developed application for distribution using both the new "Startup" and "Package and Deployment" wizards (that incudes "autorun"...
3
by: Claire | last post by:
Sorry for such a daft question. Ive been following some tutorials on creating windows services. Ive not done them before. In my original debuggable windows form application, I create my worker...
42
by: Martin Jørgensen | last post by:
Hi, I'm trying to move a matlab program into c language. For those who knows matlab, this is the line I want to program in c: hx(1:nx,1:ny) = 0; % nx=10, ny=10 It works on a 2-dimensional...
0
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
2
by: BadFeeling | last post by:
Hi all, I have started with css some months ago, and though I'm feeling more and more safe and comfortable, some parts of css still don't make perfect sense to me. Right now I have this...
3
by: Jack | last post by:
Hi there, In a submit button event, I need to open a (server-side) file relative to the folder containing the ".aspx" file. What's the correct way to locate the ".aspx" folder itself inside my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.