将XML转换为jaxb模型

时间:2013-11-12 20:50:54

标签: java xml jaxb

下面是我的xml,我想生成jaxb模型,我的目标是提取数据    从项目节点。应该使用什么注释或    我的jaxb模型类看起来如何?提前谢谢。

<channel>
    <title>VIAF Search: Roy Tennant</title>
    <link>...</link>
    <description>VIAF: Results of search: cql.any all Roy Tennant</description>
    <opensearch:totalResults>8</opensearch:totalResults>
    <opensearch:startIndex>1</opensearch:startIndex>
    <opensearch:itemsPerPage>8</opensearch:itemsPerPage>
    <opensearch:link type="application/opensearchdescription+xml" 
                     href="http://viaf.org/allFieldsSearch.xml"
                     rel="search"/>
    <opensearch:Query searchTerms="Roy Tennant" role="request"/>
    <item>...</item>
    <item>
        <title>Tennant, Jeff</title>
        <link>http://viaf.org/viaf/41080217</link>
        <pubDate>Mon, 22 Feb 2010 06:44:19 GMT</pubDate>
        <guid>http://viaf.org/viaf/41080217</guid>
    </item>
    <item>...</item>
    <item>...</item>
    <item>...</item>
    <item>...</item>
    <item>...</item>
    <item>...</item>
</channel>

1 个答案:

答案 0 :(得分:0)

更新:

这篇文章适合您:http://chawlasandeep.com/jaxb-a-head-start/

这看起来像RSS,架构在这里http://rss2schema.codeplex.com/releases/view/18981

接下来从架构生成模型,例如在maven中

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <id>xjc</id>
            <goals>
                <goal>xjc</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <packageName>com.example.myschema</packageName> <!-- The name of your generated source package -->
    </configuration>
</plugin>

这将生成所有需要注释的JAXB类。