Announcement Announcement Module
No announcement yet.
HowTo: Map XML Attributes Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • HowTo: Map XML Attributes


    in my current project we need to build a batch program that reads XML data and transfers that data in to our database. After a look at the xmlJob example its easy to map a simple xml file. But we also need to map some XML attributes not only tags. Neither the sample nor the documentation I could find provided any hint at how to do it.
    Only thing I found was the framework class AttributeAlias, which seams to provide the feature. But I didn't find any documentation on how to use it.

    Does anybody have a sample of how to map attributes?

    Thanks in advance

  • #2
    The current implementation of the XML mapping uses XStream. It also uses XStream to configure itself so you can add an attribute alias with <attributeAlias> elements in the XML mapping configuration. You can also add type converters for converting Objects as a whole to and from XML if you need to override the default behaviour.

    All of this is under review and hasn't really come under any close scrutiny yet., hence the implementation might be a bit volatile. We are quite keen to use Spring OXM if at all possible - but this might be a longer term plan, because there is no support for streaming there at the moment.


    • #3
      Hi Dave. Do you have any examples of using attributeAlias? I am trying to do the same thing.




      • #4
        We don't use XStream directly any more, we delegate to Spring OXM, which wraps it in a marshaller/unmarshaller. The Xstream docos for that are here: (there's a link to the XStream website there as well). The sample job that uses XML actually happens to be an XStream example as well (see xmlStaxJob.xml).
        Last edited by Dave Syer; Apr 25th, 2008, 09:17 AM. Reason: Add ref to sample


        • #5
          I am using the marshaller and unmarshaller. I tried to set the useAttributeFor property on XStreamMarshaller using the same mechanism as you do for setting the aliases. This did not work for me and I got an error setting the wrong property type.

          If I had any control over the XML I would change the attribue to a element but I can't.