Maintenance: Planio will be observing a scheduled maintenance window this Tuesday, November 5, 2024 from 03:00 UTC until 06:30 UTC to perform urgent network maintenance in our primary data center. Your Planio account will be unavailable during this maintenance window.
How to resolved Illegal character Error
Added by Anonymous over 14 years ago
Legacy ID: #8444194 Legacy Poster: Ashish Pancholi (apancholi)
We are working a desktop application in JAVA and while dealing with XML file we are getting this Exception : [quote]net.sf.saxon.trans.XPathException: java.net.URISyntaxException: Illegal character in opaque part at index 2: net.sf.saxon.event.Emitter.makeWriter(Emitter.java:178)at net.sf.saxon.event.XMLEmitter.openDocument(XMLEmitter.java:121)at net.sf.saxon.event.XMLEmitter.startElement(XMLEmitter.java:284)at net.sf.saxon.event.UncommittedSerializer.startElement(UncommittedSerializer.java:149)at net.sf.saxon.event.NamespaceReducer.startElement(NamespaceReducer.java:72)at net.sf.saxon.dom.DOMSender.outputElement(DOMSender.java:213)at net.sf.saxon.dom.DOMSender.walkNode(DOMSender.java:162)at net.sf.saxon.dom.DOMSender.send(DOMSender.java:96)at net.sf.saxon.dom.DOMObjectModel.sendSource(DOMObjectModel.java:216)at net.sf.saxon.event.Sender.send(Sender.java:231)at net.sf.saxon.IdentityTransformer.transform(IdentityTransformer.java:32)[/quote] we are not using saxon JAR any where in code. It automatically get added to the class path and throws this exception. How can resolved this exception. [b]Can some how either resolved this exception or do not allow this jar to be added in class path. [/b]
Replies (8)
Please register to reply
RE: How to resolved Illegal character Error - Added by Anonymous over 14 years ago
Legacy ID: #8444341 Legacy Poster: Michael Kay (mhkay)
The most likely explanation for the error (but this is a fairly wild guess) is that you are using a Windows filename containing a backslash in an API where a URI is required: for example result.setSystemId("c:\temp\temp.xml") which should be result.setSystemId("file:///c:/temp/temp.xml"). A URI never uses a backslash, always a forwards slash. Some products let you get away with this, but Saxon generally sticks to the specifications. As to why Saxon is being loaded, it seems likely you are using the JAXP factory method "new TransformerFactory()" and the JAXP code has found Saxon somewhere as the first choice of transformation engine to be loaded. Setting the system property jaxp.debug="1" may shed light on the search it is conducting.
RE: How to resolved Illegal character Error - Added by Anonymous over 14 years ago
Legacy ID: #8444465 Legacy Poster: Ashish Pancholi (apancholi)
Thanks for response. The initialization of [b]StreamResult [/b] with [b]File [/b] was throwing this exception. [code]StreamResult result = new StreamResult(new File(sFilePath));[/code] and if replaced [b]File [/b] with [b]OutputStream [/b ]then it did not throw such exception. [code]StreamResult result = new StreamResult(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sFilePath), "UTF-8")));[/code] [b]Can you please help to know the reason[/b] ? Thanks once again.
RE: How to resolved Illegal character Error - Added by Anonymous over 14 years ago
Legacy ID: #8444468 Legacy Poster: Michael Kay (mhkay)
I'm surprised: I thought that (except for very early versions of the code) the StreamResult(File) constructor would always generate a valid URI. What is in sFilePath, and what Java VM are you using? Your replaced code using a FileOutputStream doesn't set the SystemId at all. For a Result object, you can usually get away with this, but it should be avoided for a Source object - it means the base URI of the XML document isn't known, which can cause problems when resolving relative URI references.
RE: How to resolved Illegal character Error - Added by Anonymous over 14 years ago
Legacy ID: #8444536 Legacy Poster: Ashish Pancholi (apancholi)
sFilePath is path of the XML from which we are dealing with. We bundled our java application and make available to user for download over internet. User download the application and installed. So the path where user has been installed the application is the current path i.e [code]"./"[/code] and we append [code]"config" + System.getProperty("file.separator") + "Product_Name.xml";[/code] to the current path. [code]File file = new File("./"+ System.getProperty("file.separator")+"config" + System.getProperty("file.separator") + "Product_Name.xml")[/code] [code]file.getAbsolutePath()[/code] is the sFilePath [b]It looks like : C:<Product_Name>.\config<Product_Name>.xml[/b] and we are using Java 1.6.
RE: How to resolved Illegal character Error - Added by Anonymous over 14 years ago
Legacy ID: #8444557 Legacy Poster: Ashish Pancholi (apancholi)
Again if we replaced [code]StreamResult result = new StreamResult(new File(sFilePath));[/code] with [code]StreamResult result = new StreamResult();[/code] [code]result.setSystemId(f);[/code] then it did not throw exception. what may be the reason ?
RE: How to resolved Illegal character Error - Added by Anonymous over 14 years ago
Legacy ID: #8444718 Legacy Poster: Michael Kay (mhkay)
I'm not able to reproduce this problem from the information given. I've looked at the source code of the StreamResult class in the JDK and it's hard to see how it can store an invalid URI in the systemId property. (Note that this is not Saxon code.) When I do StreamResult sr = new StreamResult(new File(".\a\b.xml")); System.err.prinltn(sr.getSystemId()); then I get something like: file:/C:/Users/Mike/IdeaProjects/saxon-dev/./a/b.xml which is a perfectly legal URI, and works fine with Saxon. It would be useful to see what System.err.println(result.getSystemId()) gives in your case.
RE: How to resolved Illegal character Error - Added by Anonymous over 14 years ago
Legacy ID: #8444745 Legacy Poster: Ashish Pancholi (apancholi)
[code]System.err.println(result.getSystemId())[/code] gives [b]C:<Product_Name>.\config<Product_Name>.xml[/b] And I am not sure but if you would like to reproduce then please add [b]saxon9he.jar[/b] to your project library in which you are trying to reproduce.
RE: How to resolved Illegal character Error - Added by Anonymous over 14 years ago
Legacy ID: #8444854 Legacy Poster: Michael Kay (mhkay)
Well, C:<Product_Name>.\config<Product_Name>.xml is certainly an invalid URI - not only are the backslashes illegal, but so are the angle brackets. I can't see how that could be the value of getSystemId() after calling new StreamResult(new File(...)). I could wash my hands of this because this isn't Saxon code, but I'm still intrigued. Could you please try to construct a repro: that is, a free-standing piece of Java code, ideally in the form of a JUnit test, that demonstrates this? It only needs to contain construction of a StreamResult followed by displaying the result of getSystemId().
Please register to reply