parse xml with digester

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

parse xml with digester

mteccles
Hi,

I have an XML document like follows:

<item att1="" att2="">
   <item att1="" att2="">
      <item att1="" att2="">
      </item>
   </item>
   <item att1="" att2="">
   </item>
</item>

Simply a nested structure of one complex element having two required attributes.

I write a POJO that match this structure, what code would read the xml document and parse into the Java object?
Reply | Threaded
Open this post in threaded view
|

Re: parse xml with digester

Peter_Ford
If you're mapping a POJO to XML and vice-versa, I'd consider looking at
Commons Betwixt rather than messing with Digester directly.

--Pete

mteccles <[hidden email]> wrote on 10/26/2008 06:22:59 PM:

>
> Hi,
>
> I have an XML document like follows:
>
> <item att1="" att2="">
>    <item att1="" att2="">
>       <item att1="" att2="">
>       </item>
>    </item>
>    <item att1="" att2="">
>    </item>
> </item>
>
> Simply a nested structure of one complex element having two required
> attributes.
>
> I write a POJO that match this structure, what code would read the xml
> document and parse into the Java object?
> --
> View this message in context: http://www.nabble.com/parse-xml-with-
> digester-tp20179874p20179874.html
> Sent from the Commons - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: parse xml with digester

Simon Kitching
Digester has extensive examples. See here:
 
http://svn.apache.org/repos/asf/commons/proper/digester/trunk/src/examples/

These examples are also in the digester "source distribution" download.

Regards,
Simon

[hidden email] schrieb:

> If you're mapping a POJO to XML and vice-versa, I'd consider looking at
> Commons Betwixt rather than messing with Digester directly.
>
> --Pete
>
> mteccles <[hidden email]> wrote on 10/26/2008 06:22:59 PM:
>
>  
>> Hi,
>>
>> I have an XML document like follows:
>>
>> <item att1="" att2="">
>>    <item att1="" att2="">
>>       <item att1="" att2="">
>>       </item>
>>    </item>
>>    <item att1="" att2="">
>>    </item>
>> </item>
>>
>> Simply a nested structure of one complex element having two required
>> attributes.
>>
>> I write a POJO that match this structure, what code would read the xml
>> document and parse into the Java object?


--
-- Emails in "mixed" posting style will be ignored
-- (http://en.wikipedia.org/wiki/Posting_style)


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: parse xml with digester

anon_anon
Also you may want to try to try vtd-xml, which just releases an extended
edition supporting
256 GB max file size

http://vtd-xml.sf.net


----- Original Message -----
From: "Simon Kitching" <[hidden email]>
To: "Commons Users List" <[hidden email]>
Sent: Tuesday, October 28, 2008 2:47 AM
Subject: Re: parse xml with digester


> Digester has extensive examples. See here:
>
> http://svn.apache.org/repos/asf/commons/proper/digester/trunk/src/examples/
>
> These examples are also in the digester "source distribution" download.
>
> Regards,
> Simon
>
> [hidden email] schrieb:
>> If you're mapping a POJO to XML and vice-versa, I'd consider looking at
>> Commons Betwixt rather than messing with Digester directly.
>>
>> --Pete
>>
>> mteccles <[hidden email]> wrote on 10/26/2008 06:22:59 PM:
>>
>>
>>> Hi,
>>>
>>> I have an XML document like follows:
>>>
>>> <item att1="" att2="">
>>>    <item att1="" att2="">
>>>       <item att1="" att2="">
>>>       </item>
>>>    </item>
>>>    <item att1="" att2="">
>>>    </item>
>>> </item>
>>>
>>> Simply a nested structure of one complex element having two required
>>> attributes.
>>>
>>> I write a POJO that match this structure, what code would read the xml
>>> document and parse into the Java object?
>
>
> --
> -- Emails in "mixed" posting style will be ignored
> -- (http://en.wikipedia.org/wiki/Posting_style)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: parse xml with digester

Simon Kitching
While vtd-xml looks interesting, I don't see how it is relevant to the
original question.

If the input really is as trivial as the example, then perhaps just
simply using the SAX api directly would be better.

If the example is a simplified version of the real input to be processed
(or the format might change in future), then Digester is a very good
choice. It can handle the example input, and similar structures. The
digester examples I pointed to show how to do this.

If the java object also has to be written back out to xml, then Betwixt
might be better than Digester, as digester only does xml->object.
However IMO betwixt is more complicated to use, so I would suggest
avoiding it unless two-way mapping really is needed.

Regards,
Simon

jimmy Zhang schrieb:

> Also you may want to try to try vtd-xml, which just releases an
> extended edition supporting
> 256 GB max file size
>
> http://vtd-xml.sf.net
>
>
> ----- Original Message ----- From: "Simon Kitching"
> <[hidden email]>
> To: "Commons Users List" <[hidden email]>
> Sent: Tuesday, October 28, 2008 2:47 AM
> Subject: Re: parse xml with digester
>
>
>> Digester has extensive examples. See here:
>>
>> http://svn.apache.org/repos/asf/commons/proper/digester/trunk/src/examples/
>>
>>
>> These examples are also in the digester "source distribution" download.
>>
>> Regards,
>> Simon
>>
>> [hidden email] schrieb:
>>> If you're mapping a POJO to XML and vice-versa, I'd consider looking at
>>> Commons Betwixt rather than messing with Digester directly.
>>>
>>> --Pete
>>>
>>> mteccles <[hidden email]> wrote on 10/26/2008 06:22:59
>>> PM:
>>>
>>>
>>>> Hi,
>>>>
>>>> I have an XML document like follows:
>>>>
>>>> <item att1="" att2="">
>>>>    <item att1="" att2="">
>>>>       <item att1="" att2="">
>>>>       </item>
>>>>    </item>
>>>>    <item att1="" att2="">
>>>>    </item>
>>>> </item>
>>>>
>>>> Simply a nested structure of one complex element having two required
>>>> attributes.
>>>>
>>>> I write a POJO that match this structure, what code would read the xml
>>>> document and parse into the Java object?


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: parse xml with digester

anon_anon
there is an article on this called "schemaless java xml data binding with
vtd-xml"
on onjava... that explains the relevence
----- Original Message -----
From: "Simon Kitching" <[hidden email]>
To: "Commons Users List" <[hidden email]>
Sent: Tuesday, October 28, 2008 8:43 AM
Subject: Re: parse xml with digester


> While vtd-xml looks interesting, I don't see how it is relevant to the
> original question.
>
> If the input really is as trivial as the example, then perhaps just
> simply using the SAX api directly would be better.
>
> If the example is a simplified version of the real input to be processed
> (or the format might change in future), then Digester is a very good
> choice. It can handle the example input, and similar structures. The
> digester examples I pointed to show how to do this.
>
> If the java object also has to be written back out to xml, then Betwixt
> might be better than Digester, as digester only does xml->object.
> However IMO betwixt is more complicated to use, so I would suggest
> avoiding it unless two-way mapping really is needed.
>
> Regards,
> Simon
>
> jimmy Zhang schrieb:
>> Also you may want to try to try vtd-xml, which just releases an
>> extended edition supporting
>> 256 GB max file size
>>
>> http://vtd-xml.sf.net
>>
>>
>> ----- Original Message ----- From: "Simon Kitching"
>> <[hidden email]>
>> To: "Commons Users List" <[hidden email]>
>> Sent: Tuesday, October 28, 2008 2:47 AM
>> Subject: Re: parse xml with digester
>>
>>
>>> Digester has extensive examples. See here:
>>>
>>> http://svn.apache.org/repos/asf/commons/proper/digester/trunk/src/examples/
>>>
>>>
>>> These examples are also in the digester "source distribution" download.
>>>
>>> Regards,
>>> Simon
>>>
>>> [hidden email] schrieb:
>>>> If you're mapping a POJO to XML and vice-versa, I'd consider looking at
>>>> Commons Betwixt rather than messing with Digester directly.
>>>>
>>>> --Pete
>>>>
>>>> mteccles <[hidden email]> wrote on 10/26/2008 06:22:59
>>>> PM:
>>>>
>>>>
>>>>> Hi,
>>>>>
>>>>> I have an XML document like follows:
>>>>>
>>>>> <item att1="" att2="">
>>>>>    <item att1="" att2="">
>>>>>       <item att1="" att2="">
>>>>>       </item>
>>>>>    </item>
>>>>>    <item att1="" att2="">
>>>>>    </item>
>>>>> </item>
>>>>>
>>>>> Simply a nested structure of one complex element having two required
>>>>> attributes.
>>>>>
>>>>> I write a POJO that match this structure, what code would read the xml
>>>>> document and parse into the Java object?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: parse xml with digester

Peter_Ford
In reply to this post by Simon Kitching
From experience I find Betwixt easier than Digester for this, because it
handles the Digester rules for you. Also once you've set up your mappings
and strategy objects (which isn't difficult) you get Object-to-XML and
XML-to-Object at the same time. In practise I can set up my Betwixt
configuration and test it by creating an object of the relevant class and
dumping it as XML; once I know it generates XML in the form I need, I can
then use the same configuration to read the XML without modification.

--Pete

Simon Kitching <[hidden email]> wrote on 10/28/2008 09:43:20 AM:

> While vtd-xml looks interesting, I don't see how it is relevant to the
> original question.
>
> If the input really is as trivial as the example, then perhaps just
> simply using the SAX api directly would be better.
>
> If the example is a simplified version of the real input to be processed
> (or the format might change in future), then Digester is a very good
> choice. It can handle the example input, and similar structures. The
> digester examples I pointed to show how to do this.
>
> If the java object also has to be written back out to xml, then Betwixt
> might be better than Digester, as digester only does xml->object.
> However IMO betwixt is more complicated to use, so I would suggest
> avoiding it unless two-way mapping really is needed.
>
> Regards,
> Simon
>
> jimmy Zhang schrieb:
> > Also you may want to try to try vtd-xml, which just releases an
> > extended edition supporting
> > 256 GB max file size
> >
> > http://vtd-xml.sf.net
> >
> >
> > ----- Original Message ----- From: "Simon Kitching"
> > <[hidden email]>
> > To: "Commons Users List" <[hidden email]>
> > Sent: Tuesday, October 28, 2008 2:47 AM
> > Subject: Re: parse xml with digester
> >
> >
> >> Digester has extensive examples. See here:
> >>
> >>
http://svn.apache.org/repos/asf/commons/proper/digester/trunk/src/examples/
> >>
> >>
> >> These examples are also in the digester "source distribution"
download.
> >>
> >> Regards,
> >> Simon
> >>
> >> [hidden email] schrieb:
> >>> If you're mapping a POJO to XML and vice-versa, I'd consider looking
at

> >>> Commons Betwixt rather than messing with Digester directly.
> >>>
> >>> --Pete
> >>>
> >>> mteccles <[hidden email]> wrote on 10/26/2008 06:22:59
> >>> PM:
> >>>
> >>>
> >>>> Hi,
> >>>>
> >>>> I have an XML document like follows:
> >>>>
> >>>> <item att1="" att2="">
> >>>>    <item att1="" att2="">
> >>>>       <item att1="" att2="">
> >>>>       </item>
> >>>>    </item>
> >>>>    <item att1="" att2="">
> >>>>    </item>
> >>>> </item>
> >>>>
> >>>> Simply a nested structure of one complex element having two required
> >>>> attributes.
> >>>>
> >>>> I write a POJO that match this structure, what code would read the
xml
> >>>> document and parse into the Java object?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: parse xml with digester

Jörg Schaible-3

[hidden email] wrote:

> From experience I find Betwixt easier than Digester for this,
> because it
> handles the Digester rules for you. Also once you've set up
> your mappings
> and strategy objects (which isn't difficult) you get Object-to-XML and
> XML-to-Object at the same time. In practise I can set up my Betwixt
> configuration and test it by creating an object of the
> relevant class and
> dumping it as XML; once I know it generates XML in the form I
> need, I can
> then use the same configuration to read the XML without modification.

[snip]

>>>>>> I have an XML document like follows:
>>>>>>
>>>>>> <item att1="" att2="">
>>>>>>    <item att1="" att2="">
>>>>>>       <item att1="" att2="">
>>>>>>       </item>
>>>>>>    </item>
>>>>>>    <item att1="" att2="">
>>>>>>    </item>
>>>>>> </item>
>>>>>>
>>>>>> Simply a nested structure of one complex element having two
>>>>>> required attributes.
>>>>>>
>>>>>> I write a POJO that match this structure, what code
> would read the
> xml
>>>>>> document and parse into the Java object?

An alternative could have been XStream:

======== %< ===========
class Item {
    List items;
    String attr1;
    String attr2;
}

XStream xstream = new XStream();
xstream.alias("item", Item.class);
xstream.useAttributeFor(String.class);
xstream.addImplicitCollection(Item.class, "items", "item", Item.class);
Item item = (Item)xstream.fromXML(xml);
======== %< ===========

;-)

- Jörg

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]