Hi Greg,

Sliker, Gregory <Gregory.Sliker@...> writes:

> I am trying to create Java objects from XML files I have no control over.  I
> am close to having the code working with just one annoying problem left to
> solve that involves getting the value of an attribute.  Here is a sample of
> the XML I am working with:
> <objects>
>     <object User="skippy">
>         <value1>VALUE01</value1>
>         <value2>VALUE02</value2>
>         <value3>VALUE03</value3>
>         <value4>VALUE04</value4>
>         <objectitem>
>             <desc>A thing</desc>
>             <pnumber>X12345678</pnumber>
>             <quantity>01</quantity>
>             <stuff id="L">STUFF1</stuff>
>         </objectitem>
>     </object>
>     <object User="juanita">
>         <value1>VALUE10</value1>
>         <value2>VALUE20</value2>
>         <value3>VALUE30</value3>
>         <value4>VALUE40</value4>
>         <objectitem>
>             <desc>A different thing</desc>
>             <pnumber>Z87654321</pnumber>
>             <quantity>99</quantity>
>             <stuff id="Q">STUFF2</stuff>
>         </objectitem>
>     </object>
> </objects>
>  
> My problem is within <objectitem> and getting the “id” attribute from
> <stuff>.

You cannot configure this. By default a field is either represented as attribute
or as child element, but you cannot set one field as text for the current
object. You have to use a custom converter (see the converter tutorial, it's
absolutely easy). As alternative you may register a ToAttributedValueConverter
for this type.

> I’ve tried “reversing” the process and creating XML from Java
> objects and I am “close” but I can’t seem to match the XML I need to work
> with.

That's definitely the best approach ;-)

[snip - I have to cut here, my normal news reader crashed reliable when I press
reply for your posting and Gmane don't let me post if there's too much stuff
quoted]
  
> I guess one final question would be, how do I get rid of the root tag as
> “list” and change it to “objects”?  But that I do not consider important, just
> more of a curiosity at this point.

"list" is the default alias for ArrayList. Simply define a new alias for the
latter :)

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to