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