An example of a Schema file using a custom namespace, XML file and Cast generated Java code

xiaoxiao2021-03-06  42

[Reprint]

An example of the Java code generated using a schema file, XML file, and Castor generated using a custom namespace.

Usually only used the simplest XML data binding, now test a slightly complex point example.

About XML Schema, articles:

Http://gis.pku.edu.cn/resources/tr/xml_schema.doc

You can save a lot of time to write JavaBean code through XML data binding.

An example of the Java code generated using a schema file, XML file, and Castor generated using a custom namespace.

Usually only used the simplest XML data binding, now test a slightly complex point example.

About XML Schema, articles:

Http://gis.pku.edu.cn/resources/tr/xml_schema.doc

XSD file:

Comment Describing your root element

Login Information

User Name

Password

Email Address

Email Address

Recipient Name

XML file:

lizongbo

lizongbopass

lizongbo @ gamil.com

LZB

Java file Userinfo.java:

(Loginifo.java)

/ *

* This class Was Automatic or generated with

* Castor 0.9.5.3 Using an XML

* Schema.

* $ ID $

* /

Package com.lizongbo .;

// --------------------------------- // - Imported Classes and Packages - /

// --------------------------------- /

Import java.io.ioException;

Import Java.io.Reader;

Import java.io.serializable;

Import java.io.writer;

Import org.exolab.castor.xml.marshalexception;

Import org.exolab.castor.xml.marshaller;

Import org.exolab.castor.xml.unmarshaller;

Import org.exolab.castor.xml.validationException;

Import org.xml.sax.contenthandler;

/ **

* Comment describing your root element

*

* @version $ revision $ $ DATE $

* /

Public class usrinfo imports java.io.serializable {

// -------------------------- /

// - Class / Member Variables - /

// -------------------------- /

/ **

* Login information

* /

Private com.lizongbo..loginifo _loginifo;

/ **

* Field _mailinfo

* /

Private com.lizongbo..mailinfo _mailinfo;

// ---------------- /

// - constructors - /

// ---------------- /

Public userinfo () {

Super ();

} // - com.lizongbo..ursrinfo ()

// ----------- /

// - Methods - /

// ----------- /

/ **

* Returns The value of infrest 'loginifo'. The field 'loginifo'

* HAS The FOLLOWING DESCRIPTION: Login Information

*

* @Return the value of find 'loginifo'.

* /

Public com.lizongbo..Loginifo getLoginiFo ()

{

Return THIS._LOGINIFO;

} // - com.lizongbo..Loginifo getLoginiFo ()

/ **

* Returns The value of find 'mailinfo'.

*

* @Return the value of find 'mailinfo'.

* /

Public com.lizongbo..mailinfo getmailinfo ()

{

Return THIS_MAILINFO;

} // - com.lizongbo..mailinfo getmailinfo ()

/ **

* Method Isvalid

* /

Public boolean isvalid ()

{

Try {

Validate ();

}

Catch (org.exolab.castor.xml.validationException vex) {

Return False;

}

Return True;

} // - boolean isvalid ()

/ **

* Method Marshal

*

* @Param Out * /

Public void marshal (java.io.writer out)

Throws org.exolab.castor.xml.marshalexception, org.exolab.castor.xml.validationException

{

Marshaller.Marshal (this, OUT);

} // - void Marshal (java.io.writer)

/ **

* Method Marshal

*

* @Param Handler

* /

Public void marshal (org.xml.sax.contenthandler handler)

Throws java.io.ioException, org.exolab.castor.xml.marshalexception, org.exolab.castor.xml.validationException

{

Marshaller.Marshal (this, handler);

} // - void marshal (org.xml.sax.contenthandler)

/ **

* Sets the value of infrest 'loginifo'. The Field 'Loginifo' HAS

* The Following Description: Login Information

*

* @Param loginifo The value of find 'loginifo'.

* /

Public void setLoginifo (com.lizongbo..loginifo loginifo)

{

THIS._LOGINIFO = Loginifo;

} // - void setLoginifo (com.lizongbo..loginifo)

/ **

* Sets the value of find 'MailInfo'.

*

* @Param MailInfo The Value Of Field 'MailInfo'.

* /

Public void setmailinfo (com.lizongbo..mailinfo mailinfo)

{

THIS._MAILINFO = MailInfo;

} // - void setmailinfo (com.lizongbo..mailinfo)

/ **

* Method unmarshal

*

* @Param Reader

* /

Public static java.lang.Object unmarshal (java.io.reader reader)

Throws org.exolab.castor.xml.marshalexception, org.exolab.castor.xml.validationException

{

Return (com.lizongbo..usfo) unmarshaller.unmarshal (com.lizongbo..ursrinfo.class, reader);

} // - java.lang.Object unmarshal (java.io.reader)

/ **

* Method Validate

* /

Public void validate ()

Throws org.exolab.castor.xml.validationException

{

Org.exolab.castor.xml.validator validator = new org.exolab.castor.xml.validator ();

Validator.validate (this);

} // - void validate ()

}

-------------------------------------------------- / *

* This class Was Automatic or generated with

* Castor 0.9.5.3 Using an XML

* Schema.

* $ ID $

* /

Package com.lizongbo .;

// --------------------------------- /

// - Imported Classes and PACKAGES - /

// --------------------------------- /

Import java.io.ioException;

Import Java.io.Reader;

Import java.io.serializable;

Import java.io.writer;

Import org.exolab.castor.xml.marshalexception;

Import org.exolab.castor.xml.marshaller;

Import org.exolab.castor.xml.unmarshaller;

Import org.exolab.castor.xml.validationException;

Import org.xml.sax.contenthandler;

/ **

* Class MailInfo.

*

* @version $ revision $ $ DATE $

* /

Public class mailinfo imports java.io.serializable {

// -------------------------- /

// - Class / Member Variables - /

// -------------------------- /

/ **

* Email address

* /

Private java.lang.string _addr = "lizongbo @ gamil.com";

/ **

* Recipient name

* /

Private java.lang.string _Person = "lzb";

// ---------------- /

// - constructors - /

// ---------------- /

Public MailInfo () {

Super ();

SetAddr ("Lizongbo @ gamil.com");

SetPerson ("LZB");

} // - com.lizongbo..mailinfo ()

// ----------- /

// - Methods - /

// ----------- /

/ **

* Returns the value of field 'addr'. The field 'addr' HAS THE

* FOLLOWING DESCRIPTION: Email Address

*

* @Return the value of field 'addr'.

* /

Public java.lang.string getAddr ()

{

Return THIS._ADDR;

} // - java.lang.string getaddr ()

/ **

* Returns the value of find 'Person'. The Field 'Person' HAS

* The Following Description: Recipient name

*

* @Return the value of field 'Person'.

* /

Public Java.lang.String getPerson ()

{

Return this._Person;

} // - java.lang.String getPerson ()

/ **

* Method Isvalid

* /

Public boolean isvalid ()

{

Try {

Validate ();

}

Catch (org.exolab.castor.xml.validationException vex) {

Return False;

}

Return True;

} // - boolean isvalid ()

/ **

* Method Marshal

*

* @Param Out

* /

Public void marshal (java.io.writer out)

Throws org.exolab.castor.xml.marshalexception, org.exolab.castor.xml.validationException

{

Marshaller.Marshal (this, OUT);

} // - void Marshal (java.io.writer)

/ **

* Method Marshal

*

* @Param Handler

* /

Public void marshal (org.xml.sax.contenthandler handler)

Throws java.io.ioException, org.exolab.castor.xml.marshalexception, org.exolab.castor.xml.validationException

{

Marshaller.Marshal (this, handler);

} // - void marshal (org.xml.sax.contenthandler)

/ **

* Sets the value of field 'addr'. The field 'addr' HAS THE

* FOLLOWING DESCRIPTION: Email Address

*

* @Param Addr the value of field 'addr'.

* /

Public void setaddr (java.lang.string addr)

{

THIS._ADDR = AddR;

} // - void setaddr (java.lang.string)

/ **

* Sets the value of field 'Person'. The Field 'Person' Has There

* FOLLOWING DESCRIPTION: Recipient name

*

* @Param Person the value of field 'Person'.

* /

Public void setPerson (java.lang.string person)

{

THIS._PERSON = Person;

} // - void setPerson (java.lang.string)

/ **

* Method unmarshal

*

* @Param Reader

* /

Public static java.lang.Object unmarshal (java.io.reader reader)

Throws org.exolab.castor.xml.marshalexception, org.exolab.castor.xml.validationException

{

Return (com.lizongbo..mailinfo) unmarshaller.unmarshal (com.lizongbo..mailinfo.class, reader);

} // - java.lang.Object unmarshal (java.io.reader) / **

* Method Validate

* /

Public void validate ()

Throws org.exolab.castor.xml.validationException

{

Org.exolab.castor.xml.validator validator = new org.exolab.castor.xml.validator ();

Validator.validate (this);

} // - void validate ()

}

转载请注明原文地址:https://www.9cbs.com/read-57424.html

New Post(0)