• 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

Using JAXB to unmarshal an XML file but need to ignore missing IDREF target elements

 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have a process which needs to read a rather complicated XML file and then apply a set of "override" values to the result. Using JAXB and the XML schema, we've generated Java classes to represent the data and when I use JAXB to unmarshal the main XML file, it works fine. The Override XML file, however, just contains a small number of elements which are meant to override the corresponding elements in the main XML file.

The intent is that we'll read in the main XML file which will initialize the data instance, then read in the override XML file, go through the elements contained within and update the data instance.

The problem is that the override XML file contains elements which refer to other common elements using IDREFs and these common elements are not in the override file. When we use JAXB to read in the override XML file, it replaces the reference with "null". Is there any way I can get the parser to ignore the fact that the element wants to refer to another element and just let me see what the reference id value is?

One option I can think of is to create (by hand, I guess) a set of data classes specifically for the elements used in the override files such that they don't employ the IDREFs. Then I would be able to read the raw data - but this would be a lot of work and introduce a dependency on these classes and any changes which may be made to the structure of the override XML files in the future.

Thanks for any pointers.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just wanted to pass along what I ended up doing. I read both files using XML readers, creating instances of Document objects. I then went through the elements in the "override" document and used XPaths to find the associated elements in the "base" document. I then replaced the element in the base document with the one from the override document.

Once this process is done, I then used JAXB to unmarshal the resulting XML into the generated classes (the classes generated by JAXB based on the schema for the XML).

This gives me exactly what I was looking for. Thanks to anyone who looked at my question.
 
Something about .... going for a swim. With this tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic