Solved

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

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

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
thanks
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
NP. Glad to help   = )
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

11 Experts available now in Live!

Get 1:1 Help Now