Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-10
5
Medium Priority
?
676 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 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview
Suggested Courses

916 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