Solved

XSD Restrictions

Posted on 2011-03-10
1
618 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
[X]
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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

724 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