?
Solved

XSD Restrictions

Posted on 2011-03-10
1
Medium Priority
?
626 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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, …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

762 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