开发者

Meaning of xsd:simpleContent

开发者 https://www.devze.com 2023-03-19 20:14 出处:网络
I just want to know for开发者_高级运维 what and when: <xsd:simpleContent> ... </xsd:simpleContent>

I just want to know for开发者_高级运维 what and when:

<xsd:simpleContent>

...

</xsd:simpleContent>

is used.


<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.


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消