【发布时间】:2015-12-04 01:26:40
【问题描述】:
我有这样开头的 XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<interface name="AccountAPING" owner="BDP" version="1.0.0" date="now()" namespace="com.betfair.account.api"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<description>Account API-NG</description>
...
之后是各种块,比如:
<operation name="getDeveloperAppKeys" since="1.0.0">
<description>
Get all application keys owned by the given developer/vendor
</description>
<parameters>
<request/>
<simpleResponse type="list(DeveloperApp)">
<description>
A list of application keys owned by the given developer/vendor
</description>
</simpleResponse>
<exceptions>
<exception type="AccountAPINGException">
<description>Generic exception that is thrown if this operation fails for any reason.</description>
</exception>
</exceptions>
</parameters>
</operation>
........
<simpleType name="Status" type="string">
<validValues>
<value name="SUCCESS">
<description>Sucess status</description>
</value>
</validValues>
</simpleType>
........
<dataType name="TimeRange">
<description>TimeRange</description>
<parameter name="from" type="dateTime" mandatory="false">
<description>from, format: ISO 8601)</description>
</parameter>
<parameter name="to" type="dateTime" mandatory="false">
<description>to, format: ISO 8601</description>
</parameter>
</dataType>
如何使用 maven 生成 Java 代码?我尝试使用“maven-jaxb2-plugin”,但它无法解析这个结构。
请注意
- 这是一个 XML 文件,不是 xsd
- 我正在使用 Netbeans
【问题讨论】:
-
你在使用eclipse吗? maven 下载了
JaxB包?如果您在 Eclipse 中右键单击XSD文件,您可以自动生成 java 类? -
无法从 XML 生成 Java 代码。生成 java 模型需要 XSD。 xmlgrid.net/xml2xsd.html 从 XML 生成 XSD,docs.oracle.com/javaee/5/tutorial/doc/bnbah.html 从 XSD 生成 java 类。