Limit content of a tag with Schema

J

jiaqi.guo

I want to limit the content of a tag to be a string or another tag. How
can I do it?
<mytag att1="abc">Hello World</mytag>
or
<mytag att1="abc"><tag1>...</tag1></mytag>
or
<mytag att1="abc"><tag2>...</tag2></mytag>

Only pure text , one <tag1> OR one <tag2> is allowed in <mytag>
How should I define <mytag> in schema.


Thanks in advance
Jiaqi
 
S

Stan Kitsis [MSFT]

Hi Jiaqi,

You need to use a mixed model to allow both text and other elements within
<mytag> element. However, with a mixed model you cannot constrain the
position of the text nodes. So if you use it, it will allow text OR tag1 OR
tag2 OR text and tag1 OR text and tag2. Also note that in the last two
cases the text can appear before, after, or both before and after tag1 or
tag2 elements.

Here's an example:

<xs:complexType name="mytag" mixed="true">
<xs:choice minOccurs="0" maxOccurs="1">
<xs:element name="tag1" type="tag1" />
<xs:element name="tag2" type="tag2" />
</xs:choice>
</xs:complexType>
<xs:element name="mytag" type="mytag" />

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top