Total members 11889 |It is currently Thu Mar 28, 2024 12:29 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





XSD Complex Type Mixed Content :
You can add text with the elements in your XML file. You define it like in the following example
Code:
<xs:element name="student">
  <xs:complexType mixed="true">
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="age" type="xs:positiveInteger"/>
      <xs:element name="birthdate" type="xs:date"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>


This XSD document defines a structure for an XML document that contains information about a student. The student element must contain a name, age, and birthdate elements, in that order. The name element contains a string, the age element contains a positive integer and the birthdate element contains a date. It also ensures that the XML document adheres to this structure and that the data contained in each element is of the correct data type. This can be useful for ensuring data integrity and consistency when exchanging information between systems.

The xs:element element defines an element in the XML document that is being described by the XSD. The name attribute of the xs:element element specifies the name of the element. In this case, the element is called "student". The xs:complexType element defines a complex type for the "student" element, allowing it to have child elements. The mixed attribute is set to "true", which means that the element can contain both elements and text. The xs:sequence element defines a sequence of child elements. Within the sequence, there are three xs:element elements. Each of these elements defines a child element of the "student" element, with the name attribute specifying the name of the child element, and the type attribute specifying the data type of the element. The child elements are "name", "age" and "birthdate" respectively. The "name" element has a data type of "xs:string", the "age" element has a data type of "xs:positiveInteger", and the "birthdate" element has a data type of "xs:date".


XML example:

Code:
<student>
Name of the student is <name> Tom Hanks</name>
Student age is <age>22</age>
Birth date of student <birthdate>11/1/1990</birthdate>
</student>


The example confirms the structure defined by the XSD document you provided earlier. The "student" element is the root element and it contains three child elements: "name", "age", and "birthdate". The "name" element contains the text "Tom Hanks", which is the name of the student. The "age" element contains the text "22", which is the age of the student. The "birthdate" element contains the text "11/1/1990", which is the student's birthdate. It is important to note that the text within the elements is plain text and not XML elements. This is because, as specified in XSD, the complexType mixed attribute of the student element is set to true. This XML document provides specific information about a student, such as their name, age, and birthdate. It adheres to the structure and data types defined in the XSD document, ensuring that the information is organized and consistent. It can be used to exchange information about a student between systems.



Note: The mixed attribute of complexType should equal true.

You can define the name of the complex type and refer to it in the element.
Code:
<xs:element name="student" type="studentType"  />
  <xs:complexType name="studentType" mixed="true">
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="age" type="xs:positiveInteger"/>
      <xs:element name="birthdate" type="xs:date"/>
    </xs:sequence>
  </xs:complexType>


The first line defines an element called "student" that has the type "studentType". This allows the element to reference a complex type that is defined later in the document. The next section is the "xs:complexType" element with the name "studentType" and mixed attribute set to true. The "xs:sequence" element is used to define a sequence of child elements. Within the sequence, there are three "xs:element" elements, which define the child elements of the "student" element. Each element has a "name" attribute that specifies the name of the child element and a "type" attribute that specifies the data type of the element. The child elements are "name", "age" and "birthdate". In this case, the complexType named "studentType" is defined and then used as the type for "student" element. This way, the same complexType can be used for multiple elements in the XSD, making the structure and data types of the elements consistent across the document.



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : lesson8: XSD Complex Type Mixed Content
 Complex Numbers     -  
 lesson5: XSD Complex elements     -  
 Complex numbers calculator (C++)     -  
 lesson7: XSD Complex Text-Only Elements     -  
 solve the complex numbers and do operations on it     -  
 lesson9: XSD Complex Types Indicators     -  
 lesson6: XSD Complex Empty Elements     -  
 Type conversions     -  
 Type Conversion     -  
 Boolean type constant     -  



Topic Tags

XSD Elements
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com