Requiring Attributes

Contact Us or call 1-877-932-8228
Requiring Attributes

Requiring Attributes

By default, attributes are optional, but they can be required by setting the use attribute of xs:attribute to required as shown below.

Code Sample:

Attributes/Demos/Author6.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
---- C O D E   O M I T T E D ----

				<xs:element name="Name">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="FirstName">
								<xs:complexType>
									<xs:simpleContent>
										<xs:extension base="xs:string">
											<xs:attribute name="Full" type="xs:boolean" default="true"/>
										</xs:extension>
									</xs:simpleContent>
								</xs:complexType>
							</xs:element>
							<xs:element name="LastName" type="xs:string"/>
						</xs:sequence>
						<xs:attribute name="Pseudonym" type="xs:boolean" fixed="true"/>
						<xs:attribute name="HomePage" type="xs:anyURI" use="required"/>
					</xs:complexType>
				</xs:element>
---- C O D E   O M I T T E D ----

</xs:schema>
Next