Creating Documents  «Prev  Next»

Lesson 5 Working with mixed content
ObjectiveCreate a well-formed document from text.

XML Mixed Content Application

XML elements can include a combination of data and other elements.
In the book catalog example, the XML file was structured such that every individual element either contained other elements, such as
  1. <BOOK> and
  2. <TITLE>, or
  3. data,
such as a name or an ISBN number.
This is referred to as the mixed content model.
There are situations where the use of the mixed content model is desirable. For example, if you are translating a business letter into an XML document, you may use the mixed content model so that certain parts of the letter are in XML and other parts are in plain text. Note that you may also avoid using the mixed content model by creating additional XML elements. The mechanics of creating mixed content XML elements will be discussed later in the course.
View the XML diagram below to examine what happens when you mix more text with the information from the book catalog.
Mixing more text with the information from the book catalog
<xml version "1.0"
<CATALOG>

<H1>Books On Hand</H1>

<P>

The following is @ list of books ve have available for sale
Prices available upon request.

<>

<BO0K
Book Title:  <TITLE>-A Certain dustice</ TITLE
Book Author:  <AUTHOR>P.D. Jawes</ AUTHOR
Published: <YEAR-PUBLISHED- 1998</YEAR-PUBLISHED
ISBN-0975401091</ISEN

</B00K>

<BO0K>
Book Title:  <TITLE>+Ashworth Hal1</TITLE>
Book Author:  <AUTHOR>-Anne Perry</ AUTHOR>
Published: <YEAR-PUBLISHED> 1997 </YEAR-PUBLISHED>
ISBN: -0449908445</ISBN>

</B00K>

<BO0K
Book Title:  <TITLE> MPL.A. Confidential</ TITLE
Book Author:  <AUTHDR>Jaues Ellroy</AUTHOR-
Published: <YEAR-PUBLISHED- 1997 /YEAR-PUBLISHED
Tse -<ISEN- 0446674249</ISEN>

</B00K>

<BO0K
Book Title:  <TITLE>Shadow Wouan</ TITLE
Book Author:  <AUTHOR-Thouas Perry</AUTHOR-
Published: <YEAR-PUBLISHED- 1997 /YEAR-PUBLISHED
Tse <ISEN-0679453024</ISEN

</B00K>

</CATALOG>

Mixing more text with the information from the book catalog

This XML document is considerably different in terms of the look and the intermingling of text with tags and text inside the BOOK element. Yet this still meets the rules for well-formedness and would be considered an XML document. A mixed complex type element can contain attributes, elements, and text.
The next lesson shows you how to add clarity and information to XML documents.