Home > Articles > Web Services > XML

Valid XML Instances

This chapter is from the book

How Do You Recognize Data Structure?

The XML document listings you reviewed today, particularly Listings 3.1 and 3.2, shared many of the same elements, but characterized different structures. The order of the elements was not identical even though the element names were. As a result, one of the documents was intuitive and easy to follow (Listing 3.1), and the other (Listing 3.2) was not particularly representative of the desired markup.

Structure in the Recipe Markup Language

In XML, you will need to examine your documents very closely and understand the data structures, quite apart from any concern you might have for rendering the data in a browser. During Day 2 you reviewed the structure of a recipe and created two models to depict that structure. One was a block diagram (Figure 2.5) and the other offered a tree depiction of the recipe (Figure 2.6). You chose which items on the recipe card were important enough to warrant being dealt with as separate chunks of data. You eventually created the bean_dip3.xml file, shown in Listing 3.3.

Listing 3.3  bean_dip3.xml

 1: <?xml version="1.0"?>
 2: <!-- listing 3.3 - bean_dip3.xml -->
 3:
 4: <recipe title="Devan's Bean Dip">
 5:  <ingredients>
 6:      <item quantity="1 can">refried beans</item>
 7:      <item quantity="1 can">burrito sauce</item>
 8:      <item quantity="8 oz.">cubed Jalapeno cheese</item>
 9:      <item quantity="1/2 cup">sour cream</item>
10:  </ingredients>
11:  <preparation>In medium sauce pan, heat bean
12:      and burrito sauce until bubbly.  Add cubed
13:      cheese and stir until melted. Remove from
14:      heat and stir in sour cream.</preparation>
15:      <!-- For extra spicy bean dip, add your favorite hot 
16:           sauce to the mix -->
17:  <serving>Serve as a dip with corn 
18:      tortilla chips</serving>
19: </recipe>

The process you undertook to map the structure of the recipe document was to create a model, a tree, something almost like a roadmap to the information contained on the recipe card. Then you defined element and attribute names that were self-describing and intuitive. You processed the information in a parser, thereby proving that it was machine readable and then had a look at it with your own eyes, to show that it was human intelligible. This is a fairly typical example of the approach you might take the next time you create an XML instance based on a document with a known structure. To add validity, you need only consider the rules that are associated with that structure and then author an associated schema to enforce those rules when the document is parsed. For the final recipe markup language you might have rules such as these:

  • There is one and only one recipe element—the root element—that contains all others.

  • The recipe element includes a required title attribute.

  • The recipe element must contain one each of ingredients, and preparation elements in that order, plus an optional serving element.

  • ingredients must contain at least one, and might contain any number of, item elements.

  • item elements have a required quantity attribute indicating the amount of each item needed.

You Might Already Be Using Structured Data

In business, you might already have document structures in place. In fact, some of these might even be rigidly enforced by either convention or policy. Like many companies, yours might have guidelines for correspondence, memoranda formats, invoice formats, and so on. Good document structure is typically more obvious than good data structure. When thinking about data structure, consider databases and the rigid structure enforced by integrated data dictionaries. This is a good analogy because the rules regarding database data structures, like those in XML, are more concerned about the characterization of the data than they are about how those data might be rendered in a form or a report. Dealing with output from a database requires the use of a report generator or another application, function, or query that is separate from the storage and validation of the data itself. The same is true with XML—XML on its own is all about the data and it requires the use of complementary, ancillary, technologies to produce output.

When you concern yourself with validity in XML, you are effectively concerning yourself with data structure, rather than presentation. Web developers have, for some time, had to consider the structure of e-content and the impacts of storage, retrieval, maintenance, and transfer of that material rather than merely how those data might be rendered in a browser window. Technical writers, documentation specialists and, to some degree, even attorneys creating contracts and legal briefs have had to deal with complex sets of predefined and stringently enforced document structures for many years. XML offers a means of codifying structures and sharing them with business partners and other users of information.

As noted, however, XML is all about the data. XML on its own has nothing to offer with regard to rendering of those data. So unlike a document structure that typically maps readily onto an output device designed to create paper reports, XML data structures are only meant to encapsulate the kernels of data themselves. When it comes to rendering, you'll use a variety of different, but complimentary approaches including, perhaps, cascading stylesheets, the Extensible Stylesheet Language (XSL), a part of XSL known as the Extensible Stylesheet Language Transformations (XSLT), and scripting to render data stored in XML structures. You will have an opportunity to master many of these techniques as you read the remainder of this book.

TIP

The fact that XML has the characteristic of keeping data structures separate from style and content is part of what makes XML interoperable by nature. The same XML instance can be used to ultimately generate paper reports, create CD-ROM storage media, and present data to browsers, Web-enabled cellular phones, personal digital assistants, and a variety of other user agents.

What then is the difference between document structure and data structure? Document structure provides a reader with an organized means of quickly following the path of information delivery desired by the author. When you write a memorandum to a colleague, you typically indicate to whom it is addressed, along with your own name as the author, the date, and perhaps a subject line or priority, followed by the body of the message. The recipient perusing the document can use the document structure to quickly determine all of these components and then follow along without getting lost or distracted by details that can be scanned quickly. Data structures reflect the content and provide computer applications with a roadmap, not unlike a keyword index, to the data stored in various containers and sub-containers within the context of the whole document. In data structure, there is no qualification of the importance of one document component over another. All are equally relevant and it is up to the application or XML processor to determine how to use the data obtained from each container.

You Can Use XML to Add Structure to Unstructured Information

XML offers you an unlimited mechanism to use structured data for information transfer. In fact, with XML it is easy to mix and match structured and less structured data, including text, numeric data, and strings to produce highly customized output streams to solve particular needs. You could accomplish the same end by using a variety of programming techniques, but XML was ideally designed with this kind of need in mind.

Table 3.3 is an extract from a database that contains courses offered by an XML training organization. The format of the database table has records for each course and fields that include Course_Number, Course_Name, and Instructor.

Table 3.3  Course Listings Database Table

Course Number

Course Name

Instructor

XML111

Introductory XML

Bob Gonzales

XML333

Advanced XML

Devan Shepherd

XMT222

XMetal Core Configuration

Gene Yong

If the data in this table were stored in a comma delimited text file, the result might look something like the document shown in Listing 3.4.

Listing 3.4  Comma Delimited Text Version of Database Records

Course_Number,Course_Name,_Instructor
XML111,Introductory XML,Bob Gonzales
XML333,Advanced XML,Devan Shepherd
XMT222,XMetal Core Configuration,Gene Yong

XML provides a means to supplement these data with additional information that might be of value to humans or to computers. For instance, Listing 3.5 shows the same data included with additional information that could be used to produce a press release about upcoming course offerings.

Listing 3.5  Highly Structured Data Obtained from a Database Combined with Additional Information in XML

 1: <?xml version="1.0"?>
 2: <!-- listing 3.5 - courses.xml -->
 3:
 4: <announcement>
 5:   <dist>For Immediate Release</dist>
 6:   <to>All Potential Students</to>
 7:   <from>Devan Shepherd</from>
 8:   <subject>Public Course Offerings in August</subject>
 9:   <notice>ACME Training is pleased to announce the following 
10:      public courses, which are offered on a monthly basis.</notice>
11:   <contact>For more information, or to register for any of these courses,
12:      please visit 
13:    <Web site>http://ACME-Train.com/university</Web site></contact>
14:   <courses>
15:     <course id="XML111" instructor="Bob Gonzales">
16:      Introduction to XML</course>
17:     <course id="XML333" instructor="Devan Shepherd">
18:      Advanced XML</course>
19:     <course id="XMT222" instructor="Gene Yong">
20:      XMetal Core Configuration</course>
21:   </courses>
22: </announcement>

The XML output is now infinitely more useful than the comma delimited text version of the data, not only because of the added information, but also because of the use of attributes within the course elements. This XML source can be used to create an e-mail message, a newsletter, or other printed document. The same data can also be transformed, under program control, into another markup language for use by a commercial advertising service. Using XML technologies, you could also create output from the same source file for Web-enabled wireless devices, such as cellular phones, Personal Digital Assistants, pagers, and so on.

You will learn on Day 14 to use cascading stylesheets (CSS). On Days 15 and 16, you will learn the Extensible Stylesheet Language (XSL) and the subset of XSL, Extensible Stylesheet Language Transformations (XSLT), to style output like this for use in a browser or other user agents, devices and processors.

NOTE

Valid XML guarantees the integrity of data structure, as though a contract has been established with the XML instance. Automation of content delivery is simplified because of this guarantee and can be affected using XSLT.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020