Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / March 2008

Tip: Looking for answers? Try searching our database.

xml schema design

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy B - 26 Mar 2008 21:45 GMT
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 - 27 Mar 2008 13:23 GMT
> 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:
[quoted text clipped - 12 lines]
> 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.

Signature

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

Andy B - 27 Mar 2008 15:36 GMT
> 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?
Martin Honnen - 27 Mar 2008 15:50 GMT
>> Sounds fine to me, you might additionally restrict zip code to five
>> digits, enumerate the possible state codes.
[quoted text clipped - 4 lines]
> (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>

Signature

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

Andy B - 27 Mar 2008 18:55 GMT
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?
>>> Sounds fine to me, you might additionally restrict zip code to five
>>> digits, enumerate the possible state codes.
[quoted text clipped - 22 lines]
>     </xsd:restriction>
>   </xsl:simpleType>
Martin Honnen - 27 Mar 2008 19:05 GMT
> 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:

>> <xsd:simpleType name="USState">
>>   <xsd:restriction base="xsd:string">
[quoted text clipped - 4 lines]
>>   </xsd:restriction>
>> </xsd:simpleType>

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

Signature

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

Andy B - 27 Mar 2008 19:46 GMT
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)?
>> 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?
[quoted text clipped - 11 lines]
>
> Or are you now talking about a .NET enumeration defined with C# or VB.NET?
Martin Honnen - 28 Mar 2008 12:57 GMT
> 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.

Signature

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

Andy B - 28 Mar 2008 18:53 GMT
Makes sense to me. I added all of the state codes to the schema.

>> 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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.