Rnet
Rnet

Reputation: 5040

Jaxb combine xmls

I'm reading an xml file using Jaxb, now the contents of the xml file are increasing and the file is becoming too cumbersome to maintain, is there any way I can modularize the xml, by splitting it into multiple files? Is there anyway to do this in a simpler way in jaxb ?

Upvotes: 0

Views: 606

Answers (4)

Patrice M.
Patrice M.

Reputation: 4319

Well, yo could use the tried-and-true (yet much-disliked) ENTITY method in your XML file, e.g.

<!DOCTYPE config [
  <!ENTITY subpart1 SYSTEM 'config_subpart1.xml'>
  <!ENTITY subpart2 SYSTEM 'config_subpart2.xml'>
]>
<config>
    <!-- some top-level config items in the main file
    <item1>value</item1>
    ...
    <!-- then the external parts -->
    &subpart1;
    ...
    &subpart2;
    ...
</config>

The XML document is technically identical, and your JAXB code should work without any difference.

Upvotes: 1

Andrejs
Andrejs

Reputation: 27677

I ended up implementing my own XmlAdapter that adapts my LargeObject to special LazyLargeObjectLoader. Thus the main XML file only stores a reference to the large object's xml file (as a string) and the lazy loader loads the actual object from its own file when I request it.

This solution works well in my experience as it avoids storing everything in memory at once.

Upvotes: 0

Drona
Drona

Reputation: 7234

You can use a combination of STAX and JAXB. Use STAX to reach the element you want to read and then map the element to object using JAXB. That way you would be reading only the element required into the object. You need to design and manage your schema intelligently.

Upvotes: 0

random.learner
random.learner

Reputation: 53

You can read a large xml document chunk by chunk.

http://jaxb.java.net/guide/Dealing_with_large_documents.html
This JAXB doc says there are some example in JAXB RI distribution.

Upvotes: 0

Related Questions