• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Java XML converter to POJO  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I have been stuck on a problem for a while. I've been having trouble to convert this http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml xml document to a POJO class since there are multiple 'Cube' tags. Can anyone here help me on how a valid pojo class would look like?


this is my setup so far, but it is obviously not working.
 
Saloon Keeper
Posts: 9401
181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

  • The root isn't named Gesmes, but Envelope.
  • Envelope doesn't have a name, Sender has a name.
  • Envelope doesn't have a time, the inner Cube has a time.
  • Envelope doesn't have a list of Cube, it just has a single Cube.
  • Cube doesn't contain a Cube:currency element list, it contains a Cube element list of Cube elements.
  • You still need to set namespaces on your elements.
  •  
    Sammy Ward
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I created the following classes:



    But I now get this error: " org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.Attribute(empty=, name=name, required=true) on field 'name' private from class Sender"
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 9401
    181
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    name is not an attribute of Sender, but a child element.

    You also still need to specify the namespaces properly.
     
    Sammy Ward
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for the help so far, I'm not quite sure how to use namepaces. I have managed to convert everything except time to java classes.



    I'm not quite sure how to get the time value, would be really thankful if you could help me with that. Thanks.
     
    Stephan van Hulst
    Saloon Keeper
    Posts: 9401
    181
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well, as you can see, Envelope, subject, Sender and name use the gesmes prefix, while Cube, time, currency and rate don't use a prefix. In the document's root element, gesmes is declared as a short-hand for the "http://www.gesmes.org/xml/2002-08-01" namespace, and the default namespace is "http://www.ecb.int/vocabulary/2002-08-01/eurofxref".

    You still need to properly annotate your classes and members with these namespaces:

    Now, when you say you can't convert time, what is happening?
     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!