?
Solved

xsd design

Posted on 2011-04-22
1
Medium Priority
?
514 Views
Last Modified: 2012-05-11
I'm trying to build an xsd file to validate help xml files I am writing.

I have a node <p> that I want to have a single optional attribute (class) and allow any content under it....both text and html.  I'm getting the validation error stating that "parent element's content model is text only" when I try to add html. I don't know how to fix it.  I'm using VS 2010 to create the xsd and xml files.

Below is my xsd file

***********************
<?xml version="1.0" encoding="utf-8"?>
<schema id="helptopics"  elementFormDefault="qualified"  xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://myurl.com">
      <element name="topic">
            <complexType mixed="true">
                  <sequence>
                        <element name="title" type="string">
                        </element>
                        <element name="topicdescription" type="string" minOccurs="0">
                        </element>
                        <element name="content">
                              <complexType mixed="true">
                                    <choice minOccurs="0" maxOccurs="unbounded">
                                          <element name="p" minOccurs="0" maxOccurs="unbounded">
                                                <complexType mixed="true">
                                                      <attribute name="class" />
                                                </complexType>            
                                          </element>
                                          <element name="ul" minOccurs="0" maxOccurs="unbounded">
                                                <complexType>
                                                      <sequence minOccurs="1" maxOccurs="unbounded">
                                                            <element name="li" maxOccurs="unbounded">
                                                                  <complexType mixed="true"></complexType>
                                                            </element>
                                                      </sequence>
                                                </complexType>
                                          </element>
                                          <element name="ol" minOccurs="0" maxOccurs="unbounded">
                                                <complexType>
                                                      <choice minOccurs="1" maxOccurs="unbounded">
                                                            <element name="li" maxOccurs="unbounded">
                                                                  <complexType mixed="true">
                                                                  </complexType>
                                                            </element>
                                                      </choice>
                                                </complexType>
                                          </element>
                                          <element name="media" minOccurs="0" maxOccurs="unbounded">
                                                <complexType>
                                                      <attribute name="src">
                                                      </attribute>
                                                      <attribute name="alt" use="optional">
                                                            <simpleType>
                                                                  <restriction base="string" />
                                                            </simpleType>
                                                      </attribute>
                                                </complexType>
                                          </element>
                                    </choice>
                              </complexType>
                        </element>


                  </sequence>

            </complexType>
      </element>

</schema>
0
Comment
Question by:dbashley1
1 Comment
 
LVL 8

Accepted Solution

by:
Zlatin Zlatev earned 2000 total points
ID: 35695990
Sadly there is no easy way to define an element as containing html.
This is so, because html is effectivelly set of tags, and when "embeded" in an xml document, it is considered as part of the XML DOM.

You have the following options:
1. Include in your schema (a subset of) rules defined for xhtml schemas http://www.w3.org/TR/xhtml1-schema/#schemas However this will bloat your schema. The advantage is that you can specify which exact html tags are allowed as content.
2. Use CDATA sections and effectivelly have your html considered as text, when the xml is parsed. See http://stackoverflow.com/questions/1398571/html-inside-xml-should-i-use-cdata-or-encode-the-html The advantage is that you can have any html in the CDATA, however you may need to change the logic that currently works with your xml file.

Example of the later approach is the following XML snippet
<topic>
	<title>This is a sample with CDATA in content</title>
	<content><![CDATA[<p>You can put any html in here</p><div>Some test div</div>]]></content>
</topic>

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question