473,785 Members | 2,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 TransformerExce ption: Relative URI
"my.dtd" can not be resolved without a base URI.

How do I tell to javax.xml.trans form.Transforme r 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 TransformerFact ory.
javax.xml.trans form.Transforme rFactory tFactory =
javax.xml.trans form.Transforme rFactory.newIns tance();

// 2. Use the TransformerFact ory to process the stylesheet Source and
// generate a Transformer.
javax.xml.trans form.Transforme r transformer =
tFactory.newTra nsformer(new
javax.xml.trans form.stream.Str eamSource(xsl)) ;

//transformer.set URIResolver(new RelativeURIReso lver());

// 3. Use the Transformer to transform an XML Source and send the
// output to a Result object.
transformer.tra nsform(
new javax.xml.trans form.stream.Str eamSource(xml),
new javax.xml.trans form.stream.Str eamResult(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.xa lan.processor.T ransformerFacto ryImpl" and
"org.apache.cri mson.jaxp.Docum entBuilderFacto ryImpl" 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 9404
"Pavel" <ol*********@co mcast.net> wrote in message
news:e1******** *************** ***@posting.goo gle.com...
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 TransformerExce ption: Relative URI
"my.dtd" can not be resolved without a base URI.

How do I tell to javax.xml.trans form.Transforme r 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 setEntityResolv er 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 XMLReaderFactor y, 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 TransformerExce ption: Relative URI
"my.dtd" can not be resolved without a base URI.

How do I tell to javax.xml.trans form.Transforme r 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
11673
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
6250
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 print it out, the "&lang" gets converted into some strange character. i.e., just try: alert ("heyhey&lang=blahblah");
4
2861
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 align="right" valign="top">asdfsaf</td></tr> <tr><td align="right" valign="bottom"> <img src="images/corner.gif" width="11" height="11"></td>
0
1323
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" that is automatically customized for my application) that is a part of "Visual Studio Developer Extensions". After burning each CD, I used each copy to test installation on my own machine (after uninstalling each previous test-install of my...
3
1640
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 classes. The classes 'run' themselves using several threads and only stop when the form is closed. Now I've used these worker classes in the service application. When I try to run my service manually, I am given a message that the service stopped...
42
3168
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 array (size is 10*10), setting all the values inside the 10*10 matrix to zero. My C-function looks like this:
0
2681
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 looked for one on the net (I did browse the boost library though). It doesn't matter right now, anyway. To put it simply, Abstract Iterator is mainly a wrapper class. It helps
2
3576
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 problem: I have a large column div with text and links in it, and then some "special area links" that should be orange and different from the standard text links. But even though I have declared all colourchanges for my "special area" a tags, they just...
3
1382
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 handler? Thanks in advance.
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.