This is the fourth (and last) in this series of articles, which guides you in designing XML Schemas right from the basics without any hurdles. This part explains what indicators are and how to use them.
Designing Your Own XML Schema: Indicators - Attribute Groups in XML Schema (Page 6 of 6 )
This concept is very similar to “groups” in XML Schema (as described in the previous section). The only difference is that, instead of defining elements inside the group (as in the previous section), we define frequently repeated attributes within the group, forming an “attribute group.”
Once an “Attribute Group” is defined with its own name, it can be applied at several instances within the same schema (or even external schemas as well). Let us consider the following schema.
The most important fragment to be concentrated on is the following:
<xs:attribute name="Street" type="xs:string" />
<xs:attribute name="City" type="xs:string" />
<xs:attribute name="Zip" type="xs:string" />
The above defines that there exists three attributes, “Street,” “City” and “Zip” which are together grouped (or encapsulated) as “attrAddress.” The following code snippet makes use of it accordingly when necessary:
<xs:attributeGroup ref="attrAddress" />
The above snippet defines a new element, “ResAddress,” which would have all the attributes defined within “attrAddress.” The following is a sample XML document, which conforms to the above XML Schema:
<?xml version="1.0" encoding="UTF-8"?>
<Employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Documents and Settings\Administrator\Desktop\Employees.xsd">
From all of the articles in this series, any reader should be confident enough to design their own pretty XML schemas very easily without many problems. Though I didn’t touch the most advanced topics (yet), you can expect them soon. Keep referring to this website frequently or sign up for a newsletter to find out when new articles get published.
Any comments, suggestions, feedback, bugs, errors are highly appreciated at firstname.lastname@example.org
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.