|
|
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. |
|
Subject:
Re: Xml Schema
Answered By: maniac-ga on 17 Sep 2002 18:23 PDT Rated: |
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:
The information on page 5 of the second link which describes the use of 'mixed' content is what I was looking for. |
|
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> |
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 Home - Answers FAQ - Terms of Service - Privacy Policy |