Project

Profile

Help

URI error

Added by Anonymous over 19 years ago

Legacy ID: #3007049 Legacy Poster: Wizard1027 (wizard1027)

Hi, I'm trying to use the XPATH doc function to store the contents of a new document in a variable: <xsl:variable name="interface" select="doc('ModelInterface.xml')"/> But Saxon gives me a URI error: Invalid URI {ModelInterface.xml} - base {file:///D:/My Documents/Eclips...}: Illegal character in path at index 13: file:///D:/My Documents/Eclipse I assumed the problem was with the space, so I tried an absolute URL with the proper escapes: <xsl:variable name="interface" select="doc('file:///D:/My%20Documents/Eclipse%20Workspace/SteveResearch2/ModelInterface.xml')"/> I still get an error: Recoverable error Invalid URI {file:///D:/My%20Documents/Ecli...} - base {file:///D:/My Documents/Eclips...}: Illegal character in path at index 13: file:///D:/My Documents/Eclipse Workspace/SteveResearch2/ConstantFoldingTransformer.xsl Can anyone tell me what I'm doing wrong? Thank you, Wizard1027


Replies (5)

Please register to reply

RE: URI error - Added by Anonymous over 19 years ago

Legacy ID: #3007257 Legacy Poster: Michael Kay (mhkay)

It seems that you have escaped one of the spaces (in "My Documents") but have left another one unescaped (in "Eclipse Workspace"). Saxon is probably being unnecessarily strict here in requiring a valid URI. The spec of the doc() function requires only "a valid xs:anyURI". The difference is that xs:anyURI permits what I call "wannabe URIs" - strings that would be valid URIs if they were escaped. I'll add a TODO item to look at this some time. Michael Kay

RE: URI error - Added by Anonymous over 19 years ago

Legacy ID: #3007702 Legacy Poster: Wizard1027 (wizard1027)

But I am escaping both of the spaces in: "doc('file:///D:/My%20Documents/Eclipse%20Workspace/SteveResearch2/ModelInterface.xml')" And Saxon is complaining about the character at index 13, which is the first (apparently correct) escape (My%20Documents)...? Thanks, Wizard1027

RE: URI error - Added by Anonymous over 19 years ago

Legacy ID: #3007740 Legacy Poster: Michael Kay (mhkay)

Sorry - misread it. Although you've supplied a valid absolute URI, Saxon is still looking at the base URI, and is complaining that that isn't a valid URI. The base URI needs to be escaped as well. How are you actually running the transformation? If you run it from the command line, or from a StreamSource based on a File, Saxon should generate a correct base URI. If you supply the base URI yourself (by calling setSystemId() on the Source object) then Saxon won't verify it until it needs to be used. Michael Kay

RE: URI error - Added by Anonymous over 19 years ago

Legacy ID: #3007864 Legacy Poster: Wizard1027 (wizard1027)

I'm using StreamSource and a File (underscores replacing spaces here in an attempt to prevent line breaks): System.setProperty("javax.xml.transform.TransformerFactory","net.sf.saxon.TransformerFactoryImpl"); DocumentBuilderFactory_factory=DocumentBuilderFactory.newInstance(); try{ _File_stylesheet=_new_File(XSLTFile); _File_datafile=_new_File(sourceFile); __org.w3c.dom.Document_document; _DocumentBuilder_builder=_factory.newDocumentBuilder(); _document=_builder.parse(datafile); __//_Use_a_Transformer_for_output _TransformerFactory_tFactory=_TransformerFactory.newInstance(); _StreamSource_stylesource=_new_StreamSource(stylesheet); _Transformer_transformer=_tFactory.newTransformer(stylesource); _DOMSource_source=_new_DOMSource(document); _StringWriter_writer=_new_StringWriter(); _StreamResult_result=_new_StreamResult(writer); __transformer.transform(source,_result); __writer.flush(); __return_writer.toString(); } Is there something additional I need to do to escape the base URI? Thanks, Wizard1027

RE: URI error - Added by Anonymous over 19 years ago

Legacy ID: #3007883 Legacy Poster: Michael Kay (mhkay)

I've noticed before that StreamSource doesn't do file-to-URI conversion correctly. Unfortunately it's a core Java class, not simply an interface, so there's not much I can do about it. I usually do File file = new File(filename); StreamSource ss = new StreamSource(file); ss.setSystemId(file.toURI().toString()); which gives much better file-to-URI conversion. Incidentally, is there any particular reason you are supplying a DOMSource as the source document input? It's much more efficient to supply a StreamSource or SAXSource, and there's an added incentive now because of the DOM incompatibilities between JDK 1.4 and JDK 1.5. Michael Kay

    (1-5/5)

    Please register to reply