Note that there are some explanatory texts on larger screens.

plurals
  1. POSerializing java objects with respect to xml schema loaded at runtime
    primarykey
    data
    text
    <p>I call an XML document <em>three-layered</em> if its structure is laid out as following: the root element contains some container elements (I'll call them <em>entities</em>), each of them has some simpleType elements inside (I'll call them <em>properties</em>). Something like that:</p> <pre><code>&lt;data&gt; &lt;spaceship&gt; &lt;number&gt;1024&lt;/number&gt; &lt;name&gt;KTHX&lt;/name&gt; &lt;/spaceship&gt; &lt;spaceship&gt; &lt;number&gt;1624&lt;/number&gt; &lt;name&gt;LEXX&lt;/name&gt; &lt;/spaceship&gt; &lt;knife&gt; &lt;length&gt;10&lt;/length&gt; &lt;/knife&gt; &lt;/data&gt; </code></pre> <p>where <code>spaceship</code> is an entity, and <code>number</code> is a property. </p> <p>My problem is stated below:</p> <p><strong>Given</strong></p> <p><code>schema</code>: an <em>arbitrary</em> xsd file describing a three-layered document, loaded at runtime. <code>xmlDocument</code>: an xml document conforming to the <code>schema</code>.</p> <p><strong>Create</strong></p> <p>A <code>Map&lt;String, Map &lt;String, Object&gt;&gt;</code> containing data from the <code>xmlDocument</code>, where first key corresponds to entity, second key correponds to this entity's property, and the value corresponds to this property's value, after casting it to a proper java type (for example, if the schema sets the property value to be <code>xs:int</code>, then it should be cast to <code>Integer</code>).</p> <p>What is the easiest way to achieve this result with existing libraries?</p> <p>P. S. JAXB is not really an option here. The schema might be arbitrary and unknown at compile-time. Also I wish to avoid an excessive use of reflection (associated with converting the beans to maps). I'm looking for something that would allow me to make the typecasts while xml is being parsed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload