Google Answers Logo
View Question
 
Q: Xml Schema ( Answered 5 out of 5 stars,   1 Comment )
Question  
Subject: Xml Schema
Category: Computers > Algorithms
Asked by: skapoor-ga
List Price: $15.00
Posted: 17 Sep 2002 15:33 PDT
Expires: 17 Oct 2002 15:33 PDT
Question ID: 66159
How  create a schema element that can contain both a simpleType and
complexType value?
For example,
<msg> Hello World </msg>
and
<msg> <text> Hello World </text> </msg>

should be validated by the schema.
Answer  
Subject: Re: Xml Schema
Answered By: maniac-ga on 17 Sep 2002 18:23 PDT
Rated:5 out of 5 stars
 
Hello Skapoor,

I am not quite sure what you are looking for, but there are a number
of alternatives that may meet your need. It may be that what you
specifically asked for is not possible, but something similar will
work. I will refer to a few other sites that provide more detail than
this answer as well as pointers to further information.

First, there is an XML Schema FAQ (answers to Frequently Asked
Questions) at
  http://www.schemavalid.com/faq/xml-schema.html
There are a number of good examples in this document. Search down for
ComplexType to find an explanation of how a ComplexType can contain
other types (sequences, choices, other ComplexTypes). Search for
"xsd:union" to find an example showing two alternate definitions of a
simple type. One of these examples may answer your question directly.

Second, there are some nice tutorials as well as other reference
material at xml.com, run by O'Reilly. One that appears to be
particularly well written is at
  http://www.xml.com/pub/a/2000/11/29/schemas/part1.html
This has a pretty nice example that is worked from a relatively simple
schema to one that incorporates almost all major elements of XML. The
fourth page includes the use of xsd:union, which may handle what you
need. The fifth page introduces mixed content which may also be what
you are looking for.

There are a number of sites with additional examples in a variety of
formats (e.g., powerpoint presentation, pdf). A search phrase such as
  design xml schema simpletype complextype
can give you an idea of the scope of available information.

If these examples did not answer your question, please make a
clarification request and provide a set of examples of valid and
invalid selections.
  --Maniac
skapoor-ga rated this answer:5 out of 5 stars
The information on page 5 of the second link which describes the use
of 'mixed' content is what I was looking for.

Comments  
Subject: Re: Xml Schema
From: darrenw-ga on 18 Sep 2002 23:34 PDT
 
Here is the answer

File: Test1.xml
<Root xmlns="x-schema:/xml/schemas/Schema.xml">
<msg>
Hello
</msg>
</Root>

File: Test2.xml
<Root xmlns="x-schema:/xml/schemas/Schema.xml">
<msg>
<text>Hello</text>
</msg>
</Root>

File: Schema.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created by Darren Walker. -->
<?xml-stylesheet href="./g9boxjl2.xsl" type="text/xsl"?>
<Schema name="Test-Schema" xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="Root" model="closed" content="eltOnly" order="seq">
	<element type="msg" minOccurs="1" maxOccurs="1"/>
</ElementType>
<ElementType name="msg" model="closed" content="mixed" order="many">
	<element type="text" minOccurs="1" maxOccurs="1"/>
</ElementType>
<ElementType name="text" model="closed" content="textOnly"
dt:type="string"/>
</Schema>

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy