Xml
Knowing that XML is equivalent to browsing a database table
Knowing that XPath is equivalent to knowing the SQL
Knowing the schema is equivalent to knowing that the table is built.
So, Schema/xpath must understand, and, understand later quite easy to use.
I have had a dream for years, at least two years, and now, partly realized, because of the discovery of XMLBeans
Simply put, XMLBeans is a schema-generated class, just as we would generate class for the table structure inside the database.
This is a bean donated to Apache, from the family, to the schema support is quite comprehensive.
A simple look at a schema like this:
<xsd:element name= "Field" >
<xsd:complextype mixed= "true" >
<xsd:attribute name= "name" type= "xsd:string" use= "optional"/>
<xsd:attribute name= "label" type= "Xsd:string" use= "optional"/>
</xsd:complexType>
</xsd:element>
Run Scomp test.xsd, the generated field class is roughly as follows:
Class field{
String GetName ();
void SetName (String);
String Getlabel ();
Voidsetlabel (String);
}
If there is a complex nested complextype definition in the schema, the corresponding generation of complex classes, and support for types such as arrays.
For detailed examples please refer to Getting Started with XMLBeans
The main features of XMLBeans are as follows:
Generate strong Java types for schema
The generated type can read the document for the corresponding schema, or the DOM
Data can be validated against schema after loading.
You can obtain a corresponding SchemaType for Xmlobject to know its schema definition. It's the dom3 of the property.
Built-in XPath query
Powerful output to XML. (The simplest method is ToString ())
Schema is a powerful type, including the tree type definition language. The definition of WebService is to rely on schema.
The data table generation dataset in Virual Studio also converts the data table definition to XSD and then generates a strongly typed dataset based on the XSD.
Another powerful thing about schemas is the mutual reference between schemas. It is perfectly possible to define some business metadata in a language, and then reference it in various other shema. And these definitions are based on QName distinctions (similar to URLs). It is possible to generate a global Shema Knowledge Base, where everyone references each other, generating common standards, such as order/equipment description, etc... and indicate in a type which webservice can provide the related service for this type.
Schema-defined powerful complex structures that can be used in a variety of contexts and have previously tried to define the input and output of an entire site page using a schema. It was limited to the conditions, only using Shema to generate XSL, sample data, and database definitions. Schema is just a definition, not a qualifying transfer data must be XML. If XMLBeans is used, a strongly typed dto can be generated, and user input is validated. It even builds the client interface dynamically by using the framework of dynamic construction of Web sites, such as Echo.
May be not familiar with the XMLBeans, feel some regret the place:
1. The compiled SchemaType cannot get Org.w3c.schema .... The original class of Xmlobject under the package is not convenient if used to analyze the schema structure.
2. Dynamic construction schemas cannot be used to validate data directly, and need to be compiled into SchemaType for validation.
The schemas directory has a s4s directory, is the schema for schema, open the xmlschema.xsd will think of chicken eggs raw chicken. It's interesting to compile and see:) It would be a painful thing to write a schema without xmlspy. It is much easier to write a schema with a schema class, because there are strongly typed prompts and only the types that are allowed to exist are prompted.
The next time you're free, you'll talk about how to generate schema schemas. It's a question I've been wrestling with for days.
Some useful resources:
Let the generated class implement a specific interface.
Http://wiki.apache.org/xmlbeans/ExtensionInterfacesFeature