One .xmlbeans
Based on XML development, there are many technologies such as DOM4J (JBOSS), CASTOR, COMMON-DEGISTER (Struts), XMLBeans. There are many comparisons on these. Talk about XMLBeans here.
Xmlbeans' official address (http://xmlbeans.apache.org/). There is a detailed introduction and usage of it.
Second applicable occasion
From the experience of use, XMLBeans is more suitable for processing XML, such as SAML, LIBERTY, etc., and simple XML structures, and DOM4J or CASTOR XML mapping.
So if you have to handle a very complex Schema definition, choose XMLBeans to be better.
Third. XMLBeans use the process
1. Be familiar with XML Schema. This book is worth recommending: XML mode authority tutorial http://www.china-pub.com/computers/common/info.asp?id=8908)
2. Automatically map from Schema to Java objects.
This step can be used to build tools for XMLBeans.
The relevant Maven scripts are as follows:
Classname = "org.apache.xmlbeans.impl.tool.xmlbean" Classpathref = "maven.dependency.classpath" /> Classgendir = "$ {project.xmlbeans.classgendir}" Destfile = "$ {project.xmlbeans.destfile}" debug = "true" ClasspathRef = "maven.dependency.classpath"> xmlbean>
-> goal> This script calls the ANT script of XMLBeans (see the XMLBeans document) generated a framework that can handle Schema. 3. Eliminate XML using XMLBeans Depending on the SCHEMA's generating framework, you can handle the XML instance that meets the schema defined. This is very similar to the EMF framework under Eclipse. Two most important methods for the XMLBeans framework: a) Factory is used to parse XML, such as portletApptype portletApp = portletApptype.Factory.Parse (file); Need to be reminded, ONE: PARSE parameters can be various types, but it is best to be a stream. If it is File directly Type, in a web environment, an error is an error is Content Is Not ALLOWED IN ProLog. TWO: When using JBoss, you do not need to use Jaxen this package. B) XMLText () can export the data of the object to XML format, and not necessarily the root element. Take a look at the code segment below: Read the startup parameters from portlet.xml. Public Static Properties GetInitParamprops (PortletType portlet) { Properties PROPS = New Properties (); INITPARAMTYPE [] INITS = portlet.getinitparamarray (); For (int i = 0; i Props.SetProperty (Inits [i] .Getname (). getStringValue (), inInts [i] GetStringValue ()); } Return prOPs; } 4. Summary Use XMLBeans to handle XML, simple. High efficiency (you can look at the xmlbeans architect blog: http: //davidbau.com/). It is more difficult to deal with simple XML structures, you have to define a SCHEMA to automatically generate XMLBeans Framework. And Schema itself is a language. It is recommended to use XML SPY (Home Edition to be free) to write Schema. Below this schema is my portal layout's schema, and the effect of using XMLBeans is very good. XML Version = "1.0" Encoding = "UTF-8"?> xsd: unique> xsd: element> xsd: sequence> xsd: complexType> xsd: sequence> xsd: complexType> xsd: sequence> xsd: extension> xsd: complexContent> xsd: complexType> xsd: sequence> xsd: extension> xsd: complexContent> xsd: complexType> xsd: unique> xsd: element> xsd: sequence> xsd: extension> xsd: complexContent> xsd: complexType> xsd: unique> xsd: element> xsd: sequence> xsd: extension> xsd: complexContent> xsd: complexType> xsd: unique> xsd: element> xsd: sequence> xsd: extension> xsd: complexContent> xsd: complexType> xsd: sequence> xsd: extension> xsd: complexContent> xsd: complexType> xsd: schema>