Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Question on parsing XML using XALAN command line utility

 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

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

org.apache.xalan.xslt.Process

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.

Or
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.....

bottomline, I do not know what can be done here
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

What version of Xalan are you using?
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

xsi:schemaLocation

and add

xsi:noNamespaceSchemaLocation

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.


Thanks


 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you've seen the command line possibilities in the latest version http://xml.apache.org/xalan-j/commandline.html?
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Martijin,

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.

Can you throw some light on this please ?



 
Martijn Verburg
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There,

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).
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!