25992

XML Schema reference

Question:

I have two XML Schemas. First (A.xsd) is located in a library jar file (mylib.jar) and the second one (B.xsd) is in my project.

I want to import A.xsd into the B.xsd and validate incoming XML via Jaxb2Marshaller embedded validator.

However I'm unable to make it work properly: it seems that inner XML validator of Jaxb2Marshaller does not understand references to files in jar-files (I just want to write something like <xs:import namespace="http://my/schema.xsd" schemaLocation="classpath:schema.xsd">).

How it could be fixed? How could library schema be referenced from a project schema?

Answer1:

Check out my answer to a previous question on how a ResourceResolver can be used to solve this problem:

<ul><li><a href="https://stackoverflow.com/questions/3558333/jaxb-schemafactory-source-order-must-follow-import-order-between-schemas/3558845#3558845" rel="nofollow">JAXB SchemaFactory source order must follow import order between schemas?</a></li> </ul>

Your implementation of LSResourceResolver will handle loading the schema from the classpath and converting it to the appropriate result.

Answer2:

You will need to configure your own resolver. Nothing in jaxb will use classpath:.

There is a JAXB sample which shows this sort of thing.

Answer3:

classpath: is not a valid url for schema location. You will have to use <a href="http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/docs/1.6/jaxb/catalog.html#ctrlresolver" rel="nofollow">XML catalogs</a> to load schemas from jars.

Recommend

  • Unmarshalling works incorrectly: javax.xml.bind.UnmarshalException: unexpected element
  • Selecting multiple elements with Selenium
  • How create references between elements in XML
  • Do commands run from current directory in a shell script?
  • Root element minOccurs or maxOccurs
  • Pointer vs Reference difference when passing Eigen objects as arguments
  • LNK1104: cannot open file 'kernel32.lib'
  • Lua: Line breaks in strings
  • Can my PDF ping my server when it is opened?
  • Is there a way to save the selected text and highlight it again once the page is refreshed?
  • Pycharm: Marking a folder as 'sources root' is not recursive for subfolders
  • Android Studio Can't Find tools.jar
  • Android Studio 1.3 RC3. Google Play services out of date. Requires 7571000 but found 6774470
  • How do I include a SWC in an AS2 Flash project?
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • D3 nodes and links from JSON with nested arrays of children
  • Using jQuery closest() method with class selector
  • Email format validation in mvc3 view
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • Array.prototype.includes - not transformed with babel
  • How to add date and time under each post in guestbook in google app engine
  • Do create extension work in single-user mode in postgres?
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How do I rollback to a specific git commit
  • Is there a mandatory requirement to switch app.yaml?
  • How to format a variable of double type
  • Comma separated Values
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • coudnt use logback because of log4j
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • How to load view controller without button in storyboard?