How to parse an XML having same tag.
How to parse an xml having same tag as given below :
<number>
<value>12</value>
<value>14</value>
</number>
If it needs to use either Vector or ArrayList then please let me know how to do it.
If possible please parse it using Digester.
Thanks in advance.
Re: How to parse an XML having same tag.
What have you tried? Where are you stuck? What did google tell you? How do you want to parse this? As a list of ints? As a single Number Object containing several ints? Something else?
Re: How to parse an XML having same tag.
Thanks for your quick reply.
I need to use either Vector or Arraylist to hold the values.
I am creating a class that have getter and setter methods for that value tag. But I don't know how to create getter and setter methods as there are two tags with same name.
I just want to know the logic.
Re: How to parse an XML having same tag.
How are you parsing it now?
Re: How to parse an XML having same tag.
Using Digester. I have already tried using other xml that have different tags.
Re: How to parse an XML having same tag.
I am not familiar with Digester. If it's a requirement to use Digester, you might be best off looking for a forum specific to that product.
Re: How to parse an XML having same tag.
If you know JAXB (using @xmlElement), can you help me.
I just need to know how to set those values to either Vector or Arraylist object using getter and setter methods.
Re: How to parse an XML having same tag.
Well, I'm still not sure how exactly you want this to be parsed. But assuming you want a list of values, I would use JAXB by defining a schema that has a maxOccurs="2" or "unlimited", so the classes generated by JAXB would contain a List of values instead of a single int. Not sure whether that helps you though.
Re: How to parse an XML having same tag.
How should I do if I don't want to use schema ?
Re: How to parse an XML having same tag.
Quote:
Originally Posted by
1bun100
How should I do if I don't want to use schema ?
That I'm not sure about. Can't you just change it to a List?
Re: How to parse an XML having same tag.
Re: How to parse an XML having same tag.
I have got a solution for this thread. I have posted it here:
How to parse an XML having same tag? - Java | DaniWeb
If any one tried different way using digester please update it here.
Re: How to parse an XML having same tag.
It would have been courteous of you to tell us you had crossposted your question on other forums. Please read this: http://www.javaprogrammingforums.com...s-posting.html