Adding Attributes to Elements with Complex Content

Contact Us or call 1-877-932-8228
Adding Attributes to Elements with Complex Content

Adding Attributes to Elements with Complex Content

Elements that have child elements are said to contain complex content. Attributes for such elements are declared after the element's model group. For example, the Name element in the XML instance below has two child elements and two attributes. Below the instance is the snippet from the Author2.xsd schema that declares the Name element.

Code Sample:

Attributes/Demos/MarkTwain2.xml
<?xml version="1.0"?>
<Author xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Author2.xsd">
	<Name Pseudonym="true" HomePage="http://www.marktwain.com">
		<FirstName>Mark</FirstName>
		<LastName>Twain</LastName>
	</Name>
</Author>

Code Sample:

Attributes/Demos/Author2.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" type="xs:string"/>
							<xs:element name="LastName" type="xs:string"/>
						</xs:sequence>
						<xs:attribute name="Pseudonym" type="xs:boolean"/>
						<xs:attribute name="HomePage" type="xs:anyURI"/>
					</xs:complexType>
				</xs:element>
---- C O D E   O M I T T E D ----

</xs:schema>
Next