开发者

dynamic java bean from XSD using java

How to create dynam开发者_开发技巧ic java bean from XSD using java. Kindly provide some samples.


u can use XStream to do it. two minutes toturial

have fun!


You can do it using JAX-B, the built-in XML-to-object binding API. No examples now; I have to go to work.

I'd recommend using IntelliJ; it can generate Java Beans from an XSD using JAX-B at the touch of a menu item. I did it last week - works great, easy to do.


<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <extension>true</extension>
                <schemaFiles>[NameofYour.xsd]</schemaFiles>
                <packageName>[package for generated code]</packageName>
                <schemaDirectory>${basedir}/src/main/resources</schemaDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

You can use something similar to above in your pom if you are using JAXB + Maven.

http://jaxb.java.net/

using command

xjc -p primer.po -d src po.xsd

The primer.po is the package name and the src is the generated codes outputing directory name.

http://www.xyzws.com/scdjws/studyguide/jaxb_samples2.0.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜