• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XML Schema validation against multiple schemas using Xerces SAX

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using Xerces-j 2.11.0 parser to validate an XML against Schema. The problem is the validating schema includes other types using xmlns: notation. These types are defined in other xsd files. When I run my validation, I get the following error:

Message: cvc-elt.1.a: Cannot find the declaration of element 'types:MyRoot'.

To fix this, I did some googling and added a ResourceResolver class as some of them suggested.



In the ResourceResolver class, I have overridden resolveResource method. I still get the same error. I dont even see that the resolveResource method is being called. I had put loggers inside the class. I thought just doing



is sufficient. Is there any wiring I am missing here. Any help or guidance in this regard will be appreciated.

NOTE: I am going for the SAX based validation because basically I need to parse the XML only once, strip off and add some stuff and validate the resultant XML. So I feel there is no need to go for DOM (using DocumentBuilderFactory stuff) for this. I might be wrong, but that's the stance I have taken. Experts, please advice.

Regards
Mahesh

 
Mahesh Chandran
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi did some googling and study of the Xerces API and did some changes:

Changed

To


Commented out the p.parse API, as I understand this obviously may not do the validation, if setValidating(false). So replaced this with:



But on running this I get the following exception (the flow now goes inside the resolveResource overidden method):

[java] java.lang.NullPointerException
[java] at sun.misc.MetaIndex.mayContain(MetaIndex.java:225)
[java] at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:747)
[java] at sun.misc.URLClassPath.getResource(URLClassPath.java:169)
[java] at sun.misc.URLClassPath.getResource(URLClassPath.java:221)
[java] at java.lang.ClassLoader.getBootstrapResource(ClassLoader.java:1150)
[java] at java.lang.ClassLoader.getResource(ClassLoader.java:999)
[java] at java.lang.ClassLoader.getResource(ClassLoader.java:997)
[java] at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1192)
[java] at java.lang.Class.getResourceAsStream(Class.java:2030)
[java] at ResourceResolver.resolveResource(Unknown Source)
[java] at org.apache.xerces.util.DOMEntityResolverWrapper.resolveEntity(Unknown Source)
[java] at org.apache.xerces.impl.XMLEntityManager.resolveEntity(Unknown Source)

This is because systemId is passed as null. I have no clue how to pass this systemId from XML. Even the publicId is null. However the nameSpaceURI shows up as:

Wonder if there is a way to make this work without using the systemId and publicId but using the nameSpaceURI, since that the only thing that gets passed to resolveResource other than the baseURI. Any help is appreciated.

Regards
Mahesh
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of the "parse(File, DefaultHandler)" method, try calling the "parse(InputSource, DefaultHandler)" method.

You can create an InputSource from your File (by using the constructor which accepts an InputStream), and then you can call the InputSource's setSystemId() method. I don't know if this is the right thing to do but it isn't hard to try.
 
reply
    Bookmark Topic Watch Topic
  • New Topic