Solved

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

Posted on 2011-03-10
5
656 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
[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
  • 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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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