Mixed Content

Contact Us or call 1-877-932-8228
Mixed Content

Mixed Content

Sometimes an element will contain both child elements and character text. For example, a para element might contain mostly plain character text, but it could also have other elements (e.g, emphasis) littered throughout the character text.

As an example, let's examine look at the following XML instance document.

Code Sample:

<?xml version="1.0"?>
<Employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
		Worked for <Company>the Beatles</Company> as a 
		Worked for <Company>the Beatles</Company> as a 
			<JobTitle>Bass Guitarist</JobTitle>.
		Worked for <Company>the Wings</Company> as a 

Notice that the Bio element contains child elements Company and JobTitle as well as character text. Such elements are said to contain mixed content. The syntax for declaring elements with mixed content is shown below.

<xs:element name="ElementName"> <xs:complexType mixed="true"> <xs:sequence> <xs:element name="Child1" type="xs:string"/> <xs:element name="Child2" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>

The following example illustrates how to define this in our employee schema.

Code Sample:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
---- C O D E   O M I T T E D ----

				<xs:element name="Bio">
					<xs:complexType mixed="true">
						<xs:sequence maxOccurs="unbounded">
							<xs:element name="Company" type="xs:string"/>
							<xs:element name="JobTitle" type="xs:string"/>
---- C O D E   O M I T T E D ----