我有一个xml格式的feed,带有一些原子元素,如何将它们转换为java对象

时间:2015-10-13 12:35:31

标签: java xml parsing jaxb

我需要将此xml转换为java对象,请建议我如何做或给我一个例子

将原子提要转换为java对象与xml一样转换为java pojos ??

  <feed xmlns="http://www.w3.org/2005/Atom">
   <link href="https://exampleatomfeed.com"
     rel="current"/>
   <link href="https://exampleatomfeed.com"/?limit=25&amp;search=&   amp;direction=backward"
     rel="self"/>
   <id>urn:uuid:6e392ca6-3f9e-4e70-a2ed-81306e216ee7</id>
    <title type="text">/events</title>
   <link href="https://exampleatomfeed.com"?marker=urn:uuid:35639090-   c125-4349-bc9f-73c5f28ae98a&amp;limit=25&amp;search=&amp;direction=forward"
     rel="previous"/>
   <link href="https://exampleatomfeed.com"marker=urn:uuid:d7c91521-59c7-47de-8ebc-dcc3f1cbd621&amp;limit=25&amp;search=&amp;direction=backward"
     rel="next"/>
   <link href="https://exampleatomfeed.com"?marker=last&amp;limit=25&amp;search=&amp;direction=backward"
     rel="last"/>
   <updated>2015-10-08T09:14:28.043Z</updated>
   <atom:entry xmlns:atom="http://www.w3.org/2005/Atom">
  <atom:id>urn:uuid:35639090-c125-4349-bc9f-73c5f28ae98a</atom:id>
  <atom:category term="tid:965965"/>
  <atom:category term="rgn:ind"/>
  <atom:category term="dc:Ind"/>
  <atom:category term="iid:a0cb9f59-39f9-4dbc-b318-1d2121f8be8e"/>
  <atom:category term="example"/>
  <atom:category term="type:example"/>
  <atom:category term="example"/>
  <atom:category term="original_message_id:eda6dc40-f035-4ae5-931c-d214c184fa51"/>
  <atom:title type="text">Server</atom:title>
  <atom:content type="application/xml">
     <event xmlns="http://example.com"
            xmlns:gova="http://example.com"
            dataCenter="SYD2"
            endTime="2015-10-08T00:00:00Z"
            environment="PROD"
            id="35639090-c125-4349-bc9f-73c5f28ae98a"
            region="IND"
            resourceId="a0cb9f59-39f9-4dbc-b318-1d2121f8be8e"
            resourceName="RS-6"
            startTime="2015-10-07T00:00:00Z"
            tenantId="965965"
            type="USAGE"
            version="1">
        <nova:product bandwidthIn="127886662"
                      bandwidthOut="4236174"
                      flavorId="3"
                      flavorName="1GB Standard Instance"
                      isManaged="false"
                      osLicenseType="WINDOWS"
                      resourceType="SERVER"
                      serviceCode="ddfdffdf"
                      status="ACTIVE"
                      version="1"/>
     </event>
  </atom:content>
  <atom:link href="https://example.com/entries/urn:uuid:35639090-c125-4349-bc9f-73c5f28ae98a"
             rel="self"/>
  <atom:updated>2015-10-08T02:13:26.523Z</atom:updated>
  <atom:published>2015-10-08T02:13:26.523Z</atom:published>

   

1 个答案:

答案 0 :(得分:0)

在unmarshal时可以使用XML适配器。请看这个链接:

http://aquiseprograma.co/2015/10/como-agregar-la-etiqueta-cdata-a-etiquetas-de-un-xml-generado-por-jaxb/

这是西班牙语,但很容易理解。当编组时应用CDATA。