472,353 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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 9240
"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...
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"...
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...
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...
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
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...
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...
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.