Using Schemaoutputresolver to generate a schema for Java files

Source: Internet
Author: User

1.productannoction.java as follows:

Package Com.soa.my.java2schema;import Javax.xml.bind.annotation.xmlelement;import Javax.xml.bind.annotation.xmlrootelement;import Javax.xml.bind.annotation.XmlType; @XmlRootElement (name= " ProductAnnoaction1 ", namespace=" my.soa.java2schema.com ") @XmlType (namespace=" my.soa.java2schema.com ") public class productannoction {    private static final long serialversionuid=12345l;    @XmlElement (defaultvalue= "1.0")    static string version= "1.0";p rivate string name;private int price;public string GetName () {return name;} public void SetName (String name) {this.name = name;} public int GetPrice () {return price;} public void Setprice (int. price) {this.price = Price;} Public Productannoction () {super ();}}
2.myschemaoutputresolver.java
  <pre name= "code" class= "java" >package com.soa.my.java2schema;import java.io.file;import java.io.IOException; Import Javax.xml.bind.schemaoutputresolver;import Javax.xml.transform.result;import Javax.xml.transform.stream.streamresult;public class Myschemaoutputresolver extends Schemaoutputresolver {private File F;public myschemaoutputresolver (string string, String string2) {f=new file (string, string2);} Public Result createoutput (string NamespaceURI, String suggestedfilename) throws IOException {return new Streamresult (f) ;}}

3.java2schemabyresolver.java

Package Com.soa.my.java2schema;import Java.io.ioexception;import Javax.xml.bind.jaxbcontext;import Javax.xml.bind.jaxbexception;import Javax.xml.bind.schemaoutputresolver;public class Java2schemabyResolver {/** * @ param args * @throws jaxbexception  * schemaoutputresolver outputresolver; */schemaoutputresolver outputresolver; public static void Main (string[] args) throws Jaxbexception, IOException {        class[] Classes={productannoction.class} ;        New Java2schemabyresolver (). Excute (classes);        } private void Excute (class[] classes) throws Jaxbexception, IOException {          jaxbcontext context= Jaxbcontext.newinstance (classes);          Context.generateschema (outputresolver);} Public Java2schemabyresolver () {outputresolver=new myschemaoutputresolver ("E:/xml/xml Exercise/resolver", "MySchema.xsd") ;}}

Using Schemaoutputresolver to generate a schema for Java files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.