the <device> tag can ouccur only once where there can be an arbitrary number of <sensor> and <actuator> blocks.
in my frist approach i tried to solve it with sax, but i quickly saw that it will end up relatively complex so i discarded this way of solving the problem.
then i read about jaxb and it seems to be exactly what i need. but after working through some how to´s and introduction i still can´t solve my problem appropriate. for example i get error meesages like "if the annotation @XMLattribut is used, the class can´t have a @XMLelement tag" and so on.
(i used the variant with annotation because of the lack of a schema)
can you help me to figure out what classes i need and wich structure they need to have? the goal should be that i have a device object whith a list of components as attribute which holds the sensos and actuator objects.
thanks in advance
ps: i´ve uploaded the classes whith which i already tried and failed to solve the problem :P link:(edit: deleted)
pps: sorry for the bad englisch, as you can see from the xml i´m german...
So you are just starting with JAXB? Then I would suggest this: start with one of the JAXB tutorial examples. Next, make changes to it until you understand JAXB better. Finally, change it more until it's your requirement.
At least, that's the strategy I use for learning and applying new Java features.
Another way to get started with JAXB is to use Trang to generate an XML schema from your sample XML, then run xjc against that schema. Even if the results aren't perfect, it should give you some ideas.
i managed to annotate my classes so that they can be easily marshalled and unmarshalled.
the only problem im still struggling with is that i can´t create the leading <janitor> and trailing </janitor> tag.
my generated xml looks like this:
i know that there is the @ElementWrap annotation but unfortunately i can´t use thise in my Device Class because of the @RootElement Annotation