Groups | Blog | Home
all groups > dotnet xml > february 2005 >

dotnet xml : One Element, one attribute - simplest xsd?


Stan Kitsis [MSFT]
2/18/2005 11:11:05 AM
Hi Mark,

The following schema will do what you need:

<?xml version="1.0" encoding="utf-8" ?>

<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"

elementFormDefault="qualified"

xmlns="http://tempuri.org/XMLSchema.xsd"

xmlns:mstns="http://tempuri.org/XMLSchema.xsd"

xmlns:xs="http://www.w3.org/2001/XMLSchema">



<xs:simpleType name="my30charsType">

<xs:restriction base="xs:string">

<xs:maxLength value="30"/>

</xs:restriction>

</xs:simpleType>



<xs:element name="myElem">

<xs:complexType>

<xs:simpleContent>

<xs:extension base="my30charsType">

<xs:attribute name="myAttrib" type="my30charsType"/>

</xs:extension>

</xs:simpleContent>

</xs:complexType>

</xs:element>

</xs:schema>


--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

[quoted text, click to view]

Mark Bosley
2/18/2005 12:13:07 PM
Well, despite reading an excellent article on ComplexTypes,
I am unsure on the quickest way to express the following
<myElem myAttrib="noMoreThan30chars">
No More than 30 chars
</myElem>
Both on the string are SimpleContent, right?

Thanks, Mark

BTW the article is
http://www.xml.com/pub/a/2001/08/22/easyschema.html

Mark Bosley
2/18/2005 5:21:39 PM
Thanks, originally thinking about defining them "in-line", but your way is
cleaner.

If would have been nice if Xml Schema had defined a global types section to
keep root elements and types separate.
<schema>
<rootElements>
<foo....
</rootElements>

<globalTypes>
<fooType....
</globalTypes>
</schema>

Ciao
Mark


[quoted text, click to view]

AddThis Social Bookmark Button