Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

XSD Restrictions

Posted on 2011-03-10
1
601 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML namaspace 2 53
Fixing Non-Standard characters in text 8 111
Help with Syntax 9 45
XML Document XPath with Namespaces 3 27
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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