Solved

XSD Restrictions

Posted on 2011-03-10
1
590 Views
Last Modified: 2012-08-14
I'm trying to set some field lengths in an xsd but I get errors when using it to validate.

My XSD is as follows
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="ContactDetails" type="Contact"/>

  <xs:complexType name="Contact">
    <xs:sequence>
      <xs:element name="Surname" type="xs:string"/>
      <xs:element name="Firstname" type="xs:string"/>
      <xs:sequence>
        <xs:element name="Addresses">
          <xs:complexType>
            <xs:sequence maxOccurs="unbounded">
              <xs:element name="Address" type="Address"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="Address">
    <xs:sequence>
      <xs:element name="Line1" type="xs:nvarchar120" minOccurs="1"/>
      <xs:element name="Line2" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
  
  <xs:simpleType name="nvarchar120">
    <xs:restriction base="xs:string">
      <xs:minLength value="0"/>
      <xs:maxLength value="120"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>

Open in new window


I have 100's of fields to add and 60% are probably nvarchar120 in size. So this seems the best way to add this restriction to the xsd. However I can't see what's wrong with the above.

Help is appreciated.

For Reference the error I get is
"The 'http://www.w3.org/2001/XMLSchema:restriction' element is not supported in this context."
0
Comment
Question by:Narusegawa
1 Comment
 

Accepted Solution

by:
Narusegawa earned 0 total points
Comment Utility
Solved myself.

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xsd:element name="ContactDetails" type="Contact"/>

  <xsd:complexType name="Contact">
    <xsd:sequence>
      <xsd:element name="Surname" type="xsd:string"/>
      <xsd:element name="Firstname" type="xsd:string"/>
      <xsd:sequence>
        <xsd:element name="Addresses">
          <xsd:complexType>
            <xsd:sequence maxOccurs="unbounded">
              <xsd:element name="Address" type="Address"/>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="Address">
    <xsd:sequence>
      <xsd:element name="Line1" type="nvarchar60" minOccurs="1"/>
      <xsd:element name="Line2" type="nvarchar60" minOccurs="0"/>
    </xsd:sequence>
  </xsd:complexType>
  
	<xsd:simpleType name="nvarchar60">
		<xsd:restriction base="xsd:string">
		  <xsd:minLength value="0"/>
		  <xsd:maxLength value="2"/>
		</xsd:restriction>
  </xsd:simpleType>

</xsd:schema>

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jaxb jaxp sax dom 7 43
D3, Javascript, SVG, HTML canvas, div 2 91
Help with SimpleXML charts with PHP 4 63
XML namaspace 2 35
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now