Blog Post

XQuery for the Non-Expert – Terminology

,

Talk to the Experts

Talk to the Experts

It’s time for a new series to blog posts – XQuery for the Non-Expert.  The purpose for these posts will be to provide a foundation for using XQuery against XML.

Myself, I am not an XQuery expert.  These posts are summarizing what I know and understand.  Some of this knowledge and understanding is changing on a regular basis.  Please correct me if something incorrect is posted here.

To prepare for these new posts, we need a starting point.  The starting point is going to be a vocabulary lesson.  This way as I discuss different functions and aspects of XQuery we know what things mean.

Element Tags

Element tags are used to contain a domain of information within an XML document.  In many cases the domains of information that are represented in elements and element tags can be thought of as tables or nouns.

Element tags have opening and closing structures that define the boundary for the element.  These are identified with greater than (>) and less than (<) characters.

Let’s build out an example with element tags that defines a building.  To define the building, let’s see this represented in XML.

<Building></Building>

This is the most common method for defining an element.  There are separate opening and closing element tags; which allows information to be added to an element.  For instance if the XML document from above was suppose to represent the Sears Tower we could put this information within the element tags.

<Building>Sears Tower</Building>

Often times there will be elements in XML document that relate to other elements.  To express these relationships, elements can be nested within other elements.  This allows the XML document to build a hierarchy of information that is related to elements with the document.

To demonstrate this, let’s use the above XML example with an alternative method for defining element tag.  If there will not be any information included in an element, the opening and closing tags can be combined into a single element tag.  This alternative method is shown below with the addition of the floor element.

<Building>Sears Tower
<Floor />
</Building>

XML Attribute

More data than can be expressed through elements will nearly always be needed.  To accommodate this need, elements can have XML Attributes.  Continuing on the table and noun analogy above, attributes would be columns or adjectives.

To continue the example above, suppose the building has multiple floors, each of these floors would likely have a level designation.  Also, the Sears Tower is a skyscraper, this information would be valuable to represent in the XML document.

The following document adds elements for level and type to the element tags:

<Building type=”skyscraper”>Sears Tower
<Floor level=”1? />
<Floor level=”2? />
<Floor level=”3? />
</Building>

One important thing about elements is that when attributes are defined the values must be enclosed within double quotation marks.

XML document

I’ve talked about XML documents without a definition a few times now.  So let’s discuss XML documents and give them a whole paragraph or three.

An XML document is a collection of element tags that provide information on a domain of information.  When the XML document is complete with proper closing and ending tags and is nested properly it is considered well-formed XML document.

While an XML document might be well-formed, this does not guarantee the validity of the elements in the XML document.  The XML document may have an XML schema that it is supposed to adhere to.  But the XML document may contain or lack elements that would make it valid against the schema.

All of the building XML information above would be considered an XML document.

XML Schema

An XML schema is the collection of elements and attributes that are expected and allowed within an XML document.  Beyond the elements and attributes, the schema can also define the data types and values that are allowed for each of the elements and attributes.

XQuery

This is the query language designed to be used to query XML data.  It is able to read through XML documents and transform it from it’s native XML format into smaller pieces or to return the XML data as rows inside a result set.

XML fragment

When an XML document is broken into smaller pieces, this is often called “shredding XML”.  The smaller pieces from the XML documents are called XML fragments.
An example of an XML fragment would be taking the XML document below:

<Building type=”skyscraper”>Sears Tower
<Floor level=”1? />
<Floor level=”2? />
<Floor level=”3? />
</Building>

And removing one of the Floor elements from it, as such:

<Floor level=”2? />

This is both an XML fragment from the XML document it came from and it’s own XML document.

Wrap-Up

Ok, there is nothing in XML that is a wrap-up.  This concludes my, hopefully, simple explanation of some of the concepts and terms within XML.  If anything needs further clarity, please comment below.  I expect that as time goes on I will update and expand this post.

Related posts:

  1. Index Those Foreign Keys
  2. SSWUG Fall 2010 Virtual Conference This Month
  3. Find Tables and Columns by Data Type

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating