I'm not sure, It I have chosen the right forum for posting my question, but thought this is more appropriate as my question is more related to open source project.
I'm working on a class which would take an XML input, and then translate that to a HTML. Sounds simple The catch here is, for translating to a different format, we are using XALAN command line utility
and supplying both input xml, xsl and output file along with few parameters. This is also not a problem.
But we are not invoking this command line utility from command prompt. For executing this, we are using commons Digester to fire events based on certain patterns (there is a very good reason for doing this in our project, as we need to vary the report generation based on some matching patterns). This is also not a problem.
But the real problem is in XML. Earlier, the XSD on which the XML is based upon is in the classpath and we used "noNamespaceSchemaLocation" for declaring XSD. If we use this, my job is working great and generating the required output.
But if we declare the XSD in a URL format using "schemaLocation" attribute and if that schema is really not available at the URL or the worst, not accessible due to access restrictions, I'm getting into trouble, while translating. This is failing as the elements defind in schema are not accesible (as schema itself is not accessible) and not producing the desired output. Translation process is not throwing any exception either.
I was not recommended for changing input XML, as we may not have any control on file or the worst case, application may have only read access.
Instead they advised me to figure out a way to add "noNamespaceSchemaLocation" at runtime, so that for parsing and translation need not actually depend on schema being available at url and instead we use the schema available at classpath. Bottomline is no changes to Input XML and not guaranteed that scheme would be available/accessible at URL atleast for development and testing.
I'm seeing the problem on the invocation of org.apache.xalan.xslt.Process on XML, if the process can not find schema.
How can this be handled? Is there any way to supply XSD as a parameter during translation process, such that this new param overrides existing setting dynamically and translate to the required format as needed.
Is there any way, I can use some settings in XSL, so that it would always lookup for elements in input XML based on the schema available in classpath.....
The Xalan version I'm using is 2.5.2. Are there any command line params that can be used to override certain attributes of the elements?
In an attempt to keep my question shorter and precise, I'm just checking if there is any way to remove
from a xml document, dynamically.
I'm thinking about one way of doing this is to create DOM representation of the XML document, manipulate it and then convert back to XML. But it may be an overkill and not sure, if that would even work. I'm checking if there is any otherway of accomplishing this.
I think I did not look at the problem carefully and was completely deviated from the real problem. Keeping the command line parameters and the way of changing the attributes aside, now I'm questioningmyself, if the namespace does not exist how would transformation behave.
I thought using xsi:noNamespaceSchemaLocation instead of xsi:schemaLocation would solve my problem. But after removing xmlns attribute of the root element of my XML, transformation worked fine.
if I remove xmlns attribute from the above code, it works.
My question is, should the namespace location given through xmlns attribute be a real physically existing location. I thought it could be any URL representation. Apparently I seem to be wrong here.
Good to see that you're tracking the problem down, I think you're on the edge of having the light bulb going off here , I think that the following Light switch will help (also follow the link through the the XSL part).