Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of xsd:simpleContent

Tags:

xml

xsd

I just want to know for what and when:

<xsd:simpleContent>
...
</xsd:simpleContent>

is used.

like image 369
Gobliins Avatar asked Jul 12 '11 07:07

Gobliins


4 Answers

<xsd:simpleContent> is used when you have an element that can contain structural markup (=complex type) and the element is not allowed to contain child elements. In other words the elements content type allows only attributes and text content. Example: <foo bar="baz">foobar</foo> is an element defined with <xsd:complexType> and <xsd:simpleContent>.

It is true that using <xsd:simpleContent> involves creating a type either by restriction or by extension, but actually all complex types are implicitly either restrictions or extensions. Extension or restriction is just not necessary explicitly written in code because there is an abbreviated syntax that allows leaving them out.

like image 165
jasso Avatar answered Oct 03 '22 05:10

jasso


If you want an element whose value is a date, and which takes attributes, like this:

<event type="birthday">2011-07-17</event>

then you need a complex type with simple content (CT-SC). It's defined by taking the content type - xs:date - and extending it with an attribute definition for the "type" attribute.

like image 42
Michael Kay Avatar answered Oct 03 '22 06:10

Michael Kay


As Jordan has said it allows to extend complexType, for instance:

  <xsd:complexType name="SizeType">
      <xsd:simpleContent>
        <xsd:extension base="xsd:integer">
          <xsd:attribute name="system" type="xsd:token"/>
        </xsd:extension>
      </xsd:simpleContent>
  </xsd:complexType>

I suggest to see these examples, they have been very useful to me:

http://www.datypic.com/books/defxmlschema/examples.html

like image 32
Shilaghae Avatar answered Oct 03 '22 05:10

Shilaghae


Basically it allows you to extend a complexType element. If you had a "decimal" complexType, you could extend it with simpleContent to be a "currency" type by adding in a currency sign like $ or €, and a code such as USD or EUR. 4.75 as a decimal would become something like $4.75 USD with those extensions.

Microsoft's article is good for a basic understanding: http://msdn.microsoft.com/en-us/library/ms256106.aspx

like image 44
Jordan Avatar answered Oct 03 '22 07:10

Jordan