Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

xml schema design

Question posted by: Andy B (Guest) on March 26th, 2008 08:55 PM
I have an xml schema that I am working on. I wanted to know if it was a
normal thing to do something like this:

1. Have a ZipCode simple type that has to be 5 characters long.
2. Have a StateCode simple type that has to be 2 characters long.
3. Have an Address complex type that has:
- Street (string)
- City (sgring)
- State (StateCode) [noted in item 2 above]
- ZipCode (ZipCode) [noted in item 1 above]
4. Have a Venue complex type that has the following:
- Name (string)
- Address (Address) [noted in item 3 above]
- PhoneNumber (string)
5. Have an element that can contain only 1 instance of the Venue complex
type.



Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
March 27th, 2008
12:35 PM
#2

Re: xml schema design
Andy B wrote:
Quote:
I have an xml schema that I am working on. I wanted to know if it was a
normal thing to do something like this:
>
1. Have a ZipCode simple type that has to be 5 characters long.
2. Have a StateCode simple type that has to be 2 characters long.
3. Have an Address complex type that has:
- Street (string)
- City (sgring)
- State (StateCode) [noted in item 2 above]
- ZipCode (ZipCode) [noted in item 1 above]
4. Have a Venue complex type that has the following:
- Name (string)
- Address (Address) [noted in item 3 above]
- PhoneNumber (string)
5. Have an element that can contain only 1 instance of the Venue complex
type.


Sounds fine to me, you might additionally restrict zip code to five
digits, enumerate the possible state codes.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Andy B's Avatar
Andy B
Guest
n/a Posts
March 27th, 2008
02:45 PM
#3

Re: xml schema design
Sounds fine to me, you might additionally restrict zip code to five
Quote:
digits, enumerate the possible state codes.


I forgot about the fact that I had ZipCode set to require 5 characters. I
want to make this a 5 digit number but cant find a length property for the
int or integer data type. How would I fix this? I have it set to ZipCode
(string) - length=5. You also said to make an enum for the state codes. How
exactly do I do this?





Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
March 27th, 2008
02:55 PM
#4

Re: xml schema design
Andy B wrote:
Quote:
Quote:
>Sounds fine to me, you might additionally restrict zip code to five
>digits, enumerate the possible state codes.

>
I forgot about the fact that I had ZipCode set to require 5 characters. I
want to make this a 5 digit number but cant find a length property for the
int or integer data type. How would I fix this? I have it set to ZipCode
(string) - length=5. You also said to make an enum for the state codes. How
exactly do I do this?


Straight from <URL:http://www.w3.org/TR/xmlschema-0/is this example:

<xsd:simpleType name="USState">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="AK"/>
<xsd:enumeration value="AL"/>
<xsd:enumeration value="AR"/>
<!-- and so on ... -->
</xsd:restriction>
</xsd:simpleType>

As for the zip code, one way is with a regular expression pattern:
<xsd:simpleType name="zipType">
<xsd:restriction base="xsd:positiveInteger">
<xsd:pattern value="\d{5}"/>
</xsd:restriction>
</xsl:simpleType>



--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Andy B's Avatar
Andy B
Guest
n/a Posts
March 27th, 2008
06:05 PM
#5

Re: xml schema design
Why would it be a good idea to do an enum for the state codes instead of
just letting somebody typing it in just a string field?
"Martin Honnen" <mahotrash@yahoo.dewrote in message
news:%23NC45nBkIHA.1168@TK2MSFTNGP02.phx.gbl...
Quote:
Andy B wrote:
Quote:
Quote:
>>Sounds fine to me, you might additionally restrict zip code to five
>>digits, enumerate the possible state codes.

>>
>I forgot about the fact that I had ZipCode set to require 5 characters. I
>want to make this a 5 digit number but cant find a length property for
>the int or integer data type. How would I fix this? I have it set to
>ZipCode (string) - length=5. You also said to make an enum for the state
>codes. How exactly do I do this?

>
Straight from <URL:http://www.w3.org/TR/xmlschema-0/is this example:
>
<xsd:simpleType name="USState">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="AK"/>
<xsd:enumeration value="AL"/>
<xsd:enumeration value="AR"/>
<!-- and so on ... -->
</xsd:restriction>
</xsd:simpleType>
>
As for the zip code, one way is with a regular expression pattern:
<xsd:simpleType name="zipType">
<xsd:restriction base="xsd:positiveInteger">
<xsd:pattern value="\d{5}"/>
</xsd:restriction>
</xsl:simpleType>
>
>
>
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/




Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
March 27th, 2008
06:15 PM
#6

Re: xml schema design
Andy B wrote:
Quote:
Why would it be a good idea to do an enum for the state codes instead of
just letting somebody typing it in just a string field?


In terms of the W3C schema language I suggested an _enumeration_ below:
Quote:
Quote:
><xsd:simpleType name="USState">
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="AK"/>
> <xsd:enumeration value="AL"/>
> <xsd:enumeration value="AR"/>
> <!-- and so on ... -->
> </xsd:restriction>
></xsd:simpleType>


Or are you now talking about a .NET enumeration defined with C# or VB.NET?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Andy B's Avatar
Andy B
Guest
n/a Posts
March 27th, 2008
06:55 PM
#7

Re: xml schema design
You have the right thing. Does it do the same thing a c# enum would do?
either restrict the strings that can be used, or make useful names for
meaningless numbers (like a c# enum does)?
"Martin Honnen" <mahotrash@yahoo.dewrote in message
news:OmHhkUDkIHA.1184@TK2MSFTNGP04.phx.gbl...
Quote:
Andy B wrote:
Quote:
>Why would it be a good idea to do an enum for the state codes instead of
>just letting somebody typing it in just a string field?

>
In terms of the W3C schema language I suggested an _enumeration_ below:
>
Quote:
Quote:
>><xsd:simpleType name="USState">
>> <xsd:restriction base="xsd:string">
>> <xsd:enumeration value="AK"/>
>> <xsd:enumeration value="AL"/>
>> <xsd:enumeration value="AR"/>
>> <!-- and so on ... -->
>> </xsd:restriction>
>></xsd:simpleType>

>
Or are you now talking about a .NET enumeration defined with C# or VB.NET?
>
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/




Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
March 28th, 2008
12:05 PM
#8

Re: xml schema design
Andy B wrote:
Quote:
You have the right thing. Does it do the same thing a c# enum would do?
either restrict the strings that can be used, or make useful names for
meaningless numbers (like a c# enum does)?


The simple type I posted is a restriction of xsd:string allowing only
the enumerated string values (e.g. "AK" or "AL") to be used.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Andy B's Avatar
Andy B
Guest
n/a Posts
March 28th, 2008
06:05 PM
#9

Re: xml schema design
Makes sense to me. I added all of the state codes to the schema.


"Martin Honnen" <mahotrash@yahoo.dewrote in message
news:eTyHzrMkIHA.4664@TK2MSFTNGP03.phx.gbl...
Quote:
Andy B wrote:
Quote:
>You have the right thing. Does it do the same thing a c# enum would do?
>either restrict the strings that can be used, or make useful names for
>meaningless numbers (like a c# enum does)?

>
The simple type I posted is a restriction of xsd:string allowing only the
enumerated string values (e.g. "AK" or "AL") to be used.
>
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/




 
Not the answer you were looking for? Post your question . . .
189,938 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors