Welcome!

Industrial IoT Authors: Elizabeth White, Jyoti Bansal, Yeshim Deniz, SmartBear Blog, Liz McMillan

Related Topics: Industrial IoT

Industrial IoT: Article

Structuring Documents With XML

Structuring Documents With XML

This month's tutorial, the second in a series, picks up where last month's left off - on the path toward publishing your résumé on the Internet as an XML document. Last month (XML-J, Vol. 2, issue 5) I presented an overview of XML, described its basic building blocks, and demonstrated how to create a simple XML document.

This month, after reviewing XML's fundamental components, I'll guide you through the process of marking up a résumé with XML. In doing so the column touches on the fundamentals of structuring and marking up data as well as some of the concepts - such as hierarchical trees, nodes, and parent-child relationships - that underlie XML documents.

My objective is to help you learn how to structure a document using XML. Toward that end I'll compare three approaches to tagging based on presentation, structure, and content, thus laying the groundwork for developing a tagging strategy for résumés. Next we'll turn to a quick discussion of hierarchical trees that will supply the terminology needed to address the abstract structure of XML documents. Then we'll review last month's hands-on work and expand on it while marking up a résumé in XML. Throughout the column I'll introduce you to several new language constructs, building on last month's tutorial.

XML's Building Blocks
First we'll review the XML fundamentals covered last month peppered with a few new constructs.

Remember A simple XML document must contain at least one XML processing instruction and one or more elements, all encased in angle brackets. Processing instructions start with <? and end with ?>. XML documents begin with a processing instruction that contains an XML declaration: <?xml version="1.0" standalone="yes"?>. The stand-alone attribute, which is optional and takes yes or no as its value, specifies whether an external DTD is required. If the value is yes, an external DTD is not required.

The XML processing instruction on the first line of your document may also define the character set used, and it's generally a good idea to include it. By default XML documents use the UTF-8 encoding of Unicode. But you may use the encoding keyword to insert a declaration that specifies that set or another set, as in the following example:

<?xml version="1.0" encoding="UTF-16"
standalone="yes"?>

All the gritty details about the available character sets, including which to use when, can be found in XML in a Nutshell, by Elliotte Rusty Harold and W. Scott Means (O'Reilly). Additional technical details about character encoding can be found at www.w3.org/TR/REC-xml#charencoding.

XML documents also typically include a document type declaration that begins with <!DOCTYPE and performs two main functions:

  1. References a document type definition, or DTD
  2. Identifies the document's root element
The document type declaration may also contain an internal DTD subset, which we'll talk about in a later column.

In the following declaration the root element is the word after <!DOCTYPE:

<!DOCTYPE resume>
The document type declaration, however, is not required for the document to be well formed. A well-formed document is one that adheres to the rules of XML syntax. A valid XML document, in contrast, is one that conforms to the constraints of a DTD.

Even though the root element has been specified in the declaration, it must still appear as the document's first element:

<resume>
Besides a root element, XML documents typically contain a hierarchy of nested elements. However, there are a few restrictions on the characters that may be used in element names, especially as their first symbol. In particular, element names must begin with an underscore or a letter in either upper- or lowercase, but never a number. The tag <2001Resume> isn't permitted. After starting with a letter or underscore, a tag may contain numbers as well as other letters, hyphens, underscores, and periods.

The use of colons is illegal unless you're specifying a namespace, which will be addressed in a later column. It's also illegal to begin an element name with the letter combination of xml in any variation of upper- and lowercase. And don't forget that the sequence of symbols used in your opening and closing tags must be exactly the same.

For more information about legal and illegal tags in element and attribute names, see Robert Eckstein's XML Pocket Reference (O'Reilly). The technical details about valid XML characters are available at www.w3.org/TR/REC-xml#charsets.

All elements, including the root, may optionally take one or more attribute-value pairs. XML documents may also contain comments; they begin with .

Remember, too, that an XML document must adhere to certain markup and syntax rules to be considered well formed. First, XML is case sensitive, and the name of an opening tag must match the name of its closing tag. Second, an empty element - one that contains no other elements or text - must have a closing tag that may be combined with the starting tag. Thus, an empty element can be marked up either as <phone></phone> or as <phone/>. Third, every nonempty element's opening tag must have a corresponding closing tag. If you open an nonempty element with <resume>, it must have a corresponding closing tag of </resume> that's properly nested, which brings us to our fourth rule - XML documents may not contain any overlapping tags. Whereas <h2><i>Headline</h2></i> might work in HTML, it won't in XML. Finally, all attribute values must be enclosed in either single or double quotation marks.

When we delve into the tutorial below and the review of last month's work, you'll see how the components and rules above are used to create XML documents.

If you need more information about what I just reviewed, you may want to spend a few minutes reading up on the basics of XML. If you don't have a copy of last month's XML-Journal handy, I suggest you read the following references: the first half of Chapter 1 in Brett McLaughlin's book, Java and XML (O'Reilly); and Chapter 1 plus pages 11-16 of Chapter 2 in XML in a Nutshell. More about constructing well-formed XML can be found in the XML Pocket Reference. Taken together these readings should bring you in-line.

Tag Talk
Before marking up an isolated document with tags, there are several key markup-related decisions to make: (1) choosing a convention for tag names, (2) deciding what information to capture in attributes as opposed to child elements, and (3) choosing an approach to markup.

Besides the obvious - consistency - choosing a convention for tag names should be guided by the following criteria:

  • Ease of reading: One of the W3C's stated goals for XML documents is that they're legible to humans (as opposed to machines) and reasonably clear. Your tagging scheme should reinforce XML's self-documenting capacity and not undermine its legibility. (For more on the goals of XML see www.w3.org/TR/REC-xml#sec-origin-goals.)
  • Simplicity and ease of usability and re-creation: In general, the simpler your naming convention, the easier it'll be to apply. An easy-to-remember naming format will make writing stylesheets and DTDs easier, too.
  • Compatibility with XHTML
  • The potential for reuse with or incorporation into preexisting document type definitions (DTDs), XSL stylesheets, and tag lists
  • Ease of use of tag content, especially attribute values, in target output
Since XML doesn't restrict you to a particular case or format (other than those outlined above), you're free to choose. But in the face of the above criteria, the four main possibilities - lowercase, uppercase, initial caps, and mixed case - are not equal. Consider the following possibilities:
1. <ELEMENT>
2. <Element>
3. <element>
Compatibility with XHTML rules out option 1. In XHTML all HTML tags must be lowercase. Besides, anything written in all capital letters, even tag names, is hard to read. Option 2 is a bit easier to read; however, if you mix your tags with XHTML tags, which is useful to do at lower levels in the hierarchy of traditional documents such as software manuals, especially those destined for publication on the Web, you'll also find your tags becoming inconsistent: the tags you define begin with an uppercase letter while the XHTML tags begin with a lowercase letter.

Option 3 then seems to be the choice that would ensure the greatest consistency, especially if you're considering using XHTML in your XML markup. Using lowercase tag names also increases the potential for reusing preexisting tag lists, XSL stylesheets, and DTDs, as most XML programmers seem to prefer lowercase tags. For instance, UltraEdit, a text editor, comes with an XML tag list containing tags in lowercase.

Complex element names and the addition of attributes force us to make more decisions. Consider these tags:

4. <elementname property="hard to read">
                                                                                                    
5. <element_name property="Easy to Read">
6. <elementName property="Easy to Read">
Option 4 is difficult to read, ruling it out. Options 5 and 6 are equal in readability and the potential for reuse with existing DTDs and stylesheets. Some XML programmers use option 5 while others use 6. Others use a hyphen instead of the underscore in option 5. For its tag list UltraEdit uses option 6. Still others use option 4, as can be seen by viewing the XML markup behind the XML specification itself. It's an interesting case study in XML markup. Take a moment to study it (in Internet Explorer version 5.0 or greater, go to www.w3.org/TR/2000/REC-xml-20001006.xml).

While elements are the principal means for structuring data, attributes are typically used to capture properties of elements, and their values further modify or set a value for the property, as this tag demonstrates: <desk color="blue">.

If you choose to set your element names in lowercase, it's best, I believe, to set attribute names in lowercase, too, fostering consistency. The case of attribute values, however, is a bit trickier. The deciding factor is how they'll be used. In narrative-oriented documents I often use attribute values to contain metacontent about elements names: <section type="Introduction">. Besides making the value easier to read amid other coding, capitalizing it fosters its reuse as a headline when the document is outputted through an XSL stylesheet.

Before coding your document you'll also need to decide what information to capture in attributes as opposed to child elements. The approach I use for traditional documents is to capture metainformation but not content in attributes. XML in a Nutshell addresses the question of using attributes versus child elements in Chapter 2, "XML Fundamentals." This chapter reinforces and expands on the concepts discussed in this column.

Markup Strategies
Choosing an approach to markup is another decision you should make before you begin. The three principal markup strategies are:

  1. Presentation-based tagging
  2. Structure- or publication-oriented tagging
  3. Content- or information-based tagging
The three approaches form a dichotomy, with structure-oriented tagging hugging the middle ground, as illustrated by these examples:
Presentation: <ital>damn</ital>
Structure: <emphasis>damn</emphasis>
Content: <expletive>damn</expletive>
The markup strategy behind HTML is based almost entirely on presentation. Tags such as <h1>, <i>, and <b> indicate how content should be presented through a browser. The motivation behind using XML, however, is that it allows you to separate content from presentation and to structure data based on meaning, resulting in data and documents that are easier to reuse, manipulate, and search. Using a presentation-oriented approach exclusively defies the purpose of XML. It's better to use either a structure- or content-based approach.

Structure-based tagging is a generic, flexible approach with a wide scope, most useful when exchanging documents within a discipline or across industries. Employing a loosely structured DTD, it emphasizes elements such as <section>, <subsection>, and <paragraph>. Additional information about content is often delegated to attributes: <section id="Introduction">.

Content-based tagging is a less flexible, custom approach with a narrow scope that's most useful when modeling content around clearly defined user needs, a unique class of documents, or both. Using a tightly structured DTD, it emphasizes the use of elements such as <introduction> and <explanation>.

In reality, however, most documents intended for publication on the Internet or intranet combine all three approaches. The higher levels of the hierarchy use content-based tags, the middle levels use structure-oriented ones, and the lower levels, especially at the clausal level, may, for expedience, use some presentational tags from XHTML.

Since the focus of this column is on creating XML documents for publication on the Internet, we'll use a combination of all three approaches and learn a bit about XHTML as we do so. But as you mark up documents in XML, you'll have to evaluate the structure of your documents and how they'll be used before you decide on your own approach. Just be sure you do some planning and design before beginning the markup process. David Megginson's book, Structuring XML Documents (Prentice Hall), offers a plethora of information and good advice about choosing an approach to tagging that works best for your document or project.

Hierarchical Trees
Last month I asked you to start getting your hands dirty with XML by using a text editor such as Notepad or UltraEdit to mark up your résumé, or part of it. I suggested that you use not only elements but also attributes and that you try to create tags describing the structure or content of your résumé. I also suggested that you think about what aspects of your résumé should be captured in attributes as opposed to elements. Marking up part of your résumé in XML and debugging it in Microsoft Internet Explorer 5.0 or greater should have resulted in the document being displayed like the hypothetical résumé fragment in Figure 1.

Notice how Internet Explorer's default view for an XML document reveals its hierarchical structure. The minus and plus signs allow the document to be displayed as a collapsible outline, indeed, as a collapsible tree. In XML, various concepts, most of which spring from the way we speak about trees or families, are used to express relationships within an XML document's hierarchical structure. At the base of its hierarchy each tree has a root element, which can be seen in Internet Explorer by clicking on the first minus sign of an XML document. From the root node stems a hierarchy of other branches and leaves. Leaves are terminal elements since they don't contain child elements.

Each element in a tree structure is called a node. Relationships among nodes are expressed using metaphors borrowed from families. The root node, for instance, is the parent of all the other nodes, called children; together they enter into a parent-child relationship. Although a parent element can have multiple children, each child node has exactly one parent node. XML and its accompanying specifications such as XPointer use such constructs as parent, child, sibling, ancestor, and descendant in keywords, expressions, and functions. For more information on parent-child relationships and related constructs, see XML in a Nutshell and XML Pocket Reference.

Tutorial
Bringing to bear the XML constructs and strategies discussed above, let's step through the coding of part of an actual résumé. It is, of course, a bit more difficult than the coding behind the hypothetical one shown in Figure 1, which, perhaps somewhat naively, uses content-based tagging exclusively.

The way we intend to use the résumé determines, to a certain extent, how we should mark it up. If you're building a Web site that collects and presents résumés from job seekers, you'd probably want to employ a different markup strategy from one used to code a résumé for isolated publication on the Web. My primary objective here is to structure the content of the résumé in such a way that I can use it as the source for different output formats, not only HTML but also plain ASCII text, Portable Document Format (PDF), and Wireless Markup Language (WML). I'd also like to keep the résumé's structure somewhat flexible in case I decide to add additional material, such as a listing of computer skills or references. To mark up the résumé I'll blend all three markup approaches using both content- and structure-oriented tagging complemented by a smattering of presentation-based tagging at the lowest levels. Throughout, I'm careful to avoid duplicating information.

I begin with the usual XML processing instructions and include a character encoding declaration. The standalone value of "yes" indicates that an external DTD is not required.

<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
Next comes the document type declaration, which specifies that the document's root element is résumé.
<!DOCTYPE resume>
The markup starts with the root element and branches into two high-level structure-oriented elements: header and section. I decide to use a repeatable structure-oriented section element instead of a set of nonrepeatable content-based tags such as experience and education since it enables me to add additional sections later.

To capture the content of each section, I use the value of the ID attribute.

<resume>
<header>
<name>Jane Doe</name>
<contactInfo>
<email>[email protected]</email>
<phone/>
<addresses>
<address type="Home">
<street>10 First Avenue</street>
<city>New York</city>
<state>New York</state>
<zip>10101</zip>
</address>
</addresses>
</contactInfo>
<portfolio>Online portfolio available
at <a href="http://www.JaneDoe portfolio.com"> www.JaneDoe
portfolio.com</a></portfolio>
<objective>To obtain a position as a <emph>content
author.</emph></objective>
</header>

<section id="Qualifications">
<head>Summary of Qualifications</head>
Instead of using a content-based tag like qualification for each item in the list of qualifications, I decide to simply borrow HTML's unordered list elements:
<ul>
<li>In-depth knowledge of multimedia design.</li>
</ul>
</section>
<section id="Positions">
<head>Experience</head>
<position>Content Author</position>
<employer>XYZ Multimedia Inc.</employer>
<duration>March 1998 through February 2001</duration>
<duties>
<ul>
<li>Created multimedia content for the company's Web site.</li>
<li>Used Photoshop to refine graphics created by other authors.</li>
</ul>
</duties>
</section>

<section id="Training">
<head>Education</head>

<education>

Because the year of graduation is not always displayed in a résumé but may still be useful information to have, it is encoded using an attribute:

<degree year="1997">MA</degree>
<subject>Photography</subject>
<school>University of Washington</school>
</education>
</section>
</resume>
Hands-on Work
This is, of course, just one possible way to mark up a résumé, not necessarily the best way. Deciding on how to build a data structure for a large set of résumés that will be made available on a Web site is a complicated task requiring consideration of a number of factors, including the wholesale avoidance of duplicate information, the flexibility to accommodate résumés written in different styles and with different content, and the capability to conduct specialized searches. Mark Wilson and Tracey Wilson, in Chapters 1 and 2 of their book, XML Programming with VB and ASP (Manning), provide additional examples about how to mark up a résumé or a collection of them in XML, but more important, they also explain the motivations for wanting to do so. W. Scott Means' article "Converting Unstructured Documents to XML," at http://xml.oreilly.com/news/xmlnut3_ 0301.html, demonstrates how to isolate elements to reveal a document's underlying structure. I recommend it.

To prepare for next month's column, analyze the way in which I structured the data in this résumé and identify what, in your opinion, I should have done differently. E-mail me with your point of view and the justification for it. But don't stop there. First, revisit the way you structured your résumé after reading last month's column; finish marking it up and debugging it in Internet Explorer 5.0 or greater if you haven't done so already. Second, conceptualize the rules that should constrain a résumé's data. To spur you down this path, I suggest you read pages 89-108 of Chapter 4, "Constraining XML," in Java and XML, written by Brett McLaughlin (O'Reilly).

Next month we'll dive headfirst into constraining XML data with document type definitions, or DTDs.

More Stories By Steve Hoenisch

Steve Hoenisch is a technical writer (consultant) with Verizon
Wireless. Before becoming a technical writer and a Web developer, he
worked as a journalist and teacher. Steve has been developing Web
sites since 1996.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
DevOps is often described as a combination of technology and culture. Without both, DevOps isn't complete. However, applying the culture to outdated technology is a recipe for disaster; as response times grow and connections between teams are delayed by technology, the culture will die. A Nutanix Enterprise Cloud has many benefits that provide the needed base for a true DevOps paradigm.
SYS-CON Events announced today that Progress, a global leader in application development, has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Enterprises today are rapidly adopting the cloud, while continuing to retain business-critical/sensitive data inside the firewall. This is creating two separate data silos – one inside the firewall and the other outside the firewall. Cloud ISVs ofte...
Existing Big Data solutions are mainly focused on the discovery and analysis of data. The solutions are scalable and highly available but tedious when swapping in and swapping out occurs in disarray and thrashing takes place. The resolution for thrashing through machine learning algorithms and support nomenclature is through simple techniques. Organizations that have been collecting large customer data are increasingly seeing the need to use the data for swapping in and out and thrashing occurs ...
SYS-CON Events announced today that Outscale, a global pure play Infrastructure as a Service provider and strategic partner of Dassault Systèmes, will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Founded in 2010, Outscale simplifies infrastructure complexities and boosts the business agility of its customers. Outscale delivers a secure, reliable and industrial strength solution for its customers, which in...
SYS-CON Events announced today that DivvyCloud will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. DivvyCloud software enables organizations to achieve their cloud computing goals by simplifying and automating security, compliance and cost optimization of public and private cloud infrastructure. Using DivvyCloud, customers can leverage programmatic Bots to identify and remediate common cloud problems in rea...
Amazon started as an online bookseller 20 years ago. Since then, it has evolved into a technology juggernaut that has disrupted multiple markets and industries and touches many aspects of our lives. It is a relentless technology and business model innovator driving disruption throughout numerous ecosystems. Amazon’s AWS revenues alone are approaching $16B a year making it one of the largest IT companies in the world. With dominant offerings in Cloud, IoT, eCommerce, Big Data, AI, Digital Assis...
SYS-CON Events announced today that delaPlex will exhibit at SYS-CON's @CloudExpo, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. delaPlex pioneered Software Development as a Service (SDaaS), which provides scalable resources to build, test, and deploy software. It’s a fast and more reliable way to develop a new product or expand your in-house team.
In order to meet the rapidly changing demands of today’s customers, companies are continually forced to redefine their business strategies in order to meet these needs, stay relevant and continue to see profitable growth. IoT deployment and development is integral in this transformation, and today businesses are increasingly seeing the value of investing their resources into IoT deployments. These technologies are able increase ROI through projects such as connecting supply chains or enabling sm...
SYS-CON Events announced today that Cloudistics, an on-premises cloud computing company, has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Cloudistics delivers a complete public cloud experience with composable on-premises infrastructures to medium and large enterprises. Its software-defined technology natively converges network, storage, compute, virtualization, and management into a ...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
New competitors, disruptive technologies, and growing expectations are pushing every business to both adopt and deliver new digital services. This ‘Digital Transformation’ demands rapid delivery and continuous iteration of new competitive services via multiple channels, which in turn demands new service delivery techniques – including DevOps. In this power panel at @DevOpsSummit 20th Cloud Expo, moderated by DevOps Conference Co-Chair Andi Mann, panelists will examine how DevOps helps to meet th...
Every successful software product evolves from an idea to an enterprise system. Notably, the same way is passed by the product owner's company. In his session at 20th Cloud Expo, Oleg Lola, CEO of MobiDev, will provide a generalized overview of the evolution of a software product, the product owner, the needs that arise at various stages of this process, and the value brought by a software development partner to the product owner as a response to these needs.
SYS-CON Events announced today that A&I Solutions has been named “Bronze Sponsor” of SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Founded in 1999, A&I Solutions is a leading information technology (IT) software and services provider focusing on best-in-class enterprise solutions. By partnering with industry leaders in technology, A&I assures customers high performance levels across all IT environments including: mai...
SYS-CON Events announced today that Tappest will exhibit MooseFS at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. MooseFS is a breakthrough concept in the storage industry. It allows you to secure stored data with either duplication or erasure coding using any server. The newest – 4.0 version of the software enables users to maintain the redundancy level with even 50% less hard drive space required. The software func...
Most technology leaders, contemporary and from the hardware era, are reshaping their businesses to do software in the hope of capturing value in IoT. Although IoT is relatively new in the market, it has already gone through many promotional terms such as IoE, IoX, SDX, Edge/Fog, Mist Compute, etc. Ultimately, irrespective of the name, it is about deriving value from independent software assets participating in an ecosystem as one comprehensive solution.
SYS-CON Events announced today that EARP will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. "We are a software house, so we perfectly understand challenges that other software houses face in their projects. We can augment a team, that will work with the same standards and processes as our partners' internal teams. Our teams will deliver the same quality within the required time and budget just as our partn...
SYS-CON Events announced today that delaPlex will exhibit at SYS-CON's @ThingsExpo, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. delaPlex pioneered Software Development as a Service (SDaaS), which provides scalable resources to build, test, and deploy software. It’s a fast and more reliable way to develop a new product or expand your in-house team.
In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
SYS-CON Events announced today that Outscale will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Outscale's technology makes an automated and adaptable Cloud available to businesses, supporting them in the most complex IT projects while controlling their operational aspects. You boost your IT infrastructure's reactivity, with request responses that only take a few seconds.
SYS-CON Events announced today that Systena America will exhibit at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. Systena Group has been in business for various software development and verification in Japan, US, ASEAN, and China by utilizing the knowledge we gained from all types of device development for various industries including smartphones (Android/iOS), wireless communication, security technology and IoT serv...