Page 1 of 1

Help designing an XSD

Posted: Sun Feb 11, 2007 2:00 am
by aevarga
I am looking for help in creating an XSD definition for a paragraph of text with font changes in the middle. The original example is from W3Schools, but I want to highlight a word in mid-sentence.

Here is the XML:

Code: Select all


<?xml version="1.0"?>

<note
xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">

<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me <underline>this</underline> weekend!</body>
</note>
And here is the original XSD::

Code: Select all


<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified"><xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element></xs:schema>
My problem is trying to figure out how to define the <underline> element within the <body> element, because the <body> element already has text inside it. I'm sure it's simple, but I haven't been able to find any examples of where someone has already done this.

Thanks in advance for any help.

Alan

Posted: Wed Feb 14, 2007 6:42 pm
by sorin_ristache
Hello,

You have to allow both text content and the underline element inside the body element. For example you can use the following schema:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body">
<xs:complexType mixed="true">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="underline" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Regards,
Sorin

Posted: Sat Feb 17, 2007 5:46 pm
by aevarga
It looks like the part I was missing was

xs:complexType mixed="true"

That worked when I integrated it into my more complicated scheme (not the sample here). Thanks very much!