tags:

views:

81

answers:

1

hi

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> element, 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

+1  A: 

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

QSmienk
hi...if I may ask two questionsA) “...simpleType can only contain attributes or text. “But isn’t a type containing simple content AND attributes a complex type?
SourceC
B) “You seem to be asking questions about object behavior and not message behavior.”That’s true, but if apps or Xml schema validator didn’t treat Xml schema elements and their types as objects, wouldn’t then element declarations have different structure? Namely, wouldn’t it be easier for someone creating Xml schema ( assuming apps or validator didn’t treat elements and their types as objects ) if they could declare an element type ( containing simple content and attributes ) using <simpleType> element and not <ComplexType> element?
SourceC