Solved

Is it possible to specify the length of the fields in the XSD schema?

Posted on 2011-03-10
5
653 Views
Last Modified: 2012-05-11
I have the attached xsd schema file. Is it possible to specify the field length and the attribute length something like :
 <xs:element name="UM" type="xs:string" length = "25" />


<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="TransactionInfo">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Transactionheader">
          <xs:complexType>
            <xs:simpleContent>
              <xs:extension base="xs:string">
                <xs:attribute name="Firstname" type="xs:string" use="required" />
                <xs:attribute name="Lastname" type="xs:string" use="required" />
                <xs:attribute name="ShiptoCompany" type="xs:string" use="required" />
                <xs:attribute name="ShiptoAddress1" type="xs:string" use="required" />
                <xs:attribute name="Address2" type="xs:string" use="required" />
                <xs:attribute name="ShiptoCity" type="xs:string" use="required" />
                <xs:attribute name="ShiptoState" type="xs:string" use="required" />
                <xs:attribute name="ShiptoZip" type="xs:string" use="required" />
                <xs:attribute name="ShipToPhone" type="xs:string" use="required" />
                <xs:attribute name="Email" type="xs:string" use="required" />
                <xs:attribute name="PONumber" type="xs:int" use="required" />
                <xs:attribute name="Customattribute1" type="xs:string" use="required" />
                <xs:attribute name="Customattribute2" type="xs:string" use="required" />
                <xs:attribute name="Customattribute3" type="xs:string" use="required" />
              </xs:extension>
            </xs:simpleContent>
          </xs:complexType>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="TransactionDetail">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="SKU" type="xs:string" />
              <xs:element name="Quantity" type="xs:int" />
              <xs:element name="UM" type="xs:string" />
              <xs:element name="Customfield1" />
              <xs:element name="Customfield2" />
              <xs:element name="Customfield3" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Open in new window

0
Comment
Question by:TrialUser
  • 3
  • 2
5 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35097651
Add a "restriction" to that field:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<xs:element name="TransactionInfo">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Transactionheader">
					<xs:complexType>
						<xs:simpleContent>
							<xs:extension base="xs:string">
								<xs:attribute name="Firstname" type="xs:string" use="required"/>
								<xs:attribute name="Lastname" type="xs:string" use="required"/>
								<xs:attribute name="ShiptoCompany" type="xs:string" use="required"/>
								<xs:attribute name="ShiptoAddress1" type="xs:string" use="required"/>
								<xs:attribute name="Address2" type="xs:string" use="required"/>
								<xs:attribute name="ShiptoCity" type="xs:string" use="required"/>
								<xs:attribute name="ShiptoState" type="xs:string" use="required"/>
								<xs:attribute name="ShiptoZip" type="xs:string" use="required"/>
								<xs:attribute name="ShipToPhone" type="xs:string" use="required"/>
								<xs:attribute name="Email" type="xs:string" use="required"/>
								<xs:attribute name="PONumber" type="xs:int" use="required"/>
								<xs:attribute name="Customattribute1" type="xs:string" use="required"/>
								<xs:attribute name="Customattribute2" type="xs:string" use="required"/>
								<xs:attribute name="Customattribute3" type="xs:string" use="required"/>
							</xs:extension>
						</xs:simpleContent>
					</xs:complexType>
				</xs:element>
				<xs:element maxOccurs="unbounded" name="TransactionDetail">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="SKU" type="xs:string"/>
							<xs:element name="Quantity" type="xs:int"/>
							<xs:element name="UM">
								<xs:simpleType>
									<xs:restriction base="xs:string">
										<xs:length value="25"/>
									</xs:restriction>
								</xs:simpleType>
							</xs:element>
							<xs:element name="Customfield1"/>
							<xs:element name="Customfield2"/>
							<xs:element name="Customfield3"/>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
</xs:schema>

Open in new window

0
 

Author Comment

by:TrialUser
ID: 35097777
Ok great. what about for an attribute? For example for firstname attribute:
how can i add the length restrction?
<xs:attribute name="Firstname" type="xs:string" use="required" />
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35097836
Pretty much the same way:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="TransactionInfo">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Transactionheader">
                    <xs:complexType>
                        <xs:simpleContent>
                            <xs:extension base="xs:string">
                                <xs:attribute name="Firstname" use="required">
                                    <xs:simpleType>
                                        <xs:restriction base="xs:string">
                                            <xs:length value="25"/>
                                        </xs:restriction>
                                    </xs:simpleType>
                                </xs:attribute>
                                <xs:attribute name="Lastname" type="xs:string" use="required"/>
                                <xs:attribute name="ShiptoCompany" type="xs:string" use="required"/>
                                <xs:attribute name="ShiptoAddress1" type="xs:string" use="required"/>
                                <xs:attribute name="Address2" type="xs:string" use="required"/>
                                <xs:attribute name="ShiptoCity" type="xs:string" use="required"/>
                                <xs:attribute name="ShiptoState" type="xs:string" use="required"/>
                                <xs:attribute name="ShiptoZip" type="xs:string" use="required"/>
                                <xs:attribute name="ShipToPhone" type="xs:string" use="required"/>
                                <xs:attribute name="Email" type="xs:string" use="required"/>
                                <xs:attribute name="PONumber" type="xs:int" use="required"/>
                                <xs:attribute name="Customattribute1" type="xs:string" use="required"/>
                                <xs:attribute name="Customattribute2" type="xs:string" use="required"/>
                                <xs:attribute name="Customattribute3" type="xs:string" use="required"/>
                            </xs:extension>
                        </xs:simpleContent>
                    </xs:complexType>
                </xs:element>
                <xs:element maxOccurs="unbounded" name="TransactionDetail">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="SKU" type="xs:string"/>
                            <xs:element name="Quantity" type="xs:int"/>
                            <xs:element name="UM">
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:length value="25"/>
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:element>
                            <xs:element name="Customfield1"/>
                            <xs:element name="Customfield2"/>
                            <xs:element name="Customfield3"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Open in new window

0
 

Author Closing Comment

by:TrialUser
ID: 35134904
thanks
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35137747
NP. Glad to help   = )
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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

777 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