Solved

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

Posted on 2011-03-10
5
650 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

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

896 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

15 Experts available now in Live!

Get 1:1 Help Now