Solved

XSD Restrictions

Posted on 2011-03-10
1
592 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
ID: 35096810
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

932 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

14 Experts available now in Live!

Get 1:1 Help Now