Creating an Element with Text

To create an element that’s actually useful, we’ll want to let it contain something. We’ll start by simply creating an element whose type is xs:string:

<?xml version="1.0" encoding="UTF-8"?>
<!-- content1.xsd -->
<xs:schema 
  xmlns="http://www.oreilly.com/xslt"
  targetNamespace="http://www.oreilly.com/xslt"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="content1" type="xs:string"/>

</xs:schema>

Notice that we didn’t use <xs:complexType> this time. We simply said our element was a string. Here’s a valid document for this schema:

<?xml version="1.0" encoding="utf-8"?>
<!-- content1.xml -->
<content1
  xmlns="http://www.oreilly.com/xslt"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.oreilly.com/xslt content1.xsd">
Our element now contains some text!  It’s getting more useful 
all the time.
</content1>

Get XSLT, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.