Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML simpletype, simplecontent, complextype, complexcontent

Tags:

I'm having some confusion on the type simpletype, simplecontent, complextype and complexcontent.

I'm almost new to xsd. Can someone help to clear the confusion that giving concrete examples.

like image 738
Noor Avatar asked Oct 08 '12 09:10

Noor


People also ask

What is simpleType and complexType in XSD?

XSD elements can be of type simpleType , complexType , or anyType . An element of type simpleType contains only text. It cannot have attributes and elements. An element of type complexType can contain text, elements, and attributes.

What is complexType in XML schema?

A complex type is essentially a type definition for elements that may contain attributes and elements. An element can be declared with a type attribute that refers to a complexType element that defines the structure, content, and attributes of that element.


2 Answers

I know it's a bit late but I hope this article helps someone.

In short:

<complexType> and <simpleType> both define types. Complex types can have element descendants and attributes while simple types can't.

Complex types can have simple or complex content. Types with <complexContent> can contain child elements while those with <simpleContent> can only contain characters.

like image 72
Irina Avatar answered Sep 22 '22 00:09

Irina


What is a Complex Element?

A complex element is an XML element that contains other elements and/or attributes. There are four kinds of complex elements:

  1. empty elements
  2. elements that contain only other elements
  3. elements that contain only text
  4. elements that contain both other elements and text

Note: Each of these elements may contain attributes as well!

Examples of Complex Elements

  1. A complex XML element, "product", which is empty:
<product pid="1345"/> 
  1. A complex XML element, "employee", which contains only other elements:
<employee>     <firstname>Deepam</firstname>     <lastname>Gupta</lastname> </employee> 
  1. A complex XML element, "food", which contains only text:
<food type="dessert">Chapati</food> 
  1. A complex XML element, "description", which contains both elements and text:
<description>     It happened on <date lang="hindi">18.03.99</date> .... </description> 
like image 37
Deepam Gupta Avatar answered Sep 19 '22 00:09

Deepam Gupta