Creating elements with simple content and attributes
If we want to create an element containing both simple content ( thus one of the build-in datatypes ) and attributes, then instead of using <simpleType>
eleme开发者_运维问答nt, we instead must declare complex type and specify that this complex type will contain simple content. We do this by using <extension>
element under the <simpleContent>
element.
a) Does this new class ( derived from base type through <extension>
under <simpleContent>
element ) somehow encapsulates both the functionality of build in base type and the attribute(s)?
b) Do we use <complexType>
instead of <simpleType>
element due to the fact that derived class will be of complex type, even if it contains simple content?!
c) Do all complex types derive from some common base class?
Thanx
Please remember xml can be treated like a message and while we can serialize it into objects, the objects mainly contain properties. You seem to be asking questions about object behavior and not message behavior.
a) The complex type would contain all properties of the extended xsd and the additional elements/properties of the simpleContent nodes you add. Once serialized into an object it would contain all the properties of the complex and simple types.
b) simpleType can only contain attributes or text. They cannot contain other xsd elements. This is why we use complexType. To extend a type with more elements the complexType must be used.
c) this sounds like "is there a the base object class like in most O-O languages?" As you control the xsd, You can determine if there is a base message object that contains the base attributes and elements you want all xsds to have.
For more info please refer to:
http://www.w3schools.com/schema/default.asp
精彩评论