Saturday, April 5, 2014

70-461 Training Kit Chapter 7, Lesson 1: XML Basics Part I


This post we summarize the XML terminologies. This is the foundation for working with XML; Next few posts we'll explore how to convert SQL table to XML format and vice versa.

A simple XML document:
<?xml version="1.0" encoding="UTF-8"?>
<Customers>
    <Customer custid="1" contactname="Allen, Michael" />
    <Customer custid="2" contactname="Hassall, Mark" />
</Customers>

XML(eXtensible Markup Language) Document
Is not relational
Is Case sensitive
Is ordered (the position of elements is important)
Is well-formed when every begin tag has a matching  end tag, and if tags are nested properly such as no nested element.
Example: this is not a well formed because the elements are not nested.
<?xml version="1.0" encoding="UTF-8"?>
 <Customers>
       <Customer>
           <custid>1
                                <order>2
          </custid>
     </order>    
       </Customer>
</Customers>
Has a single root node
Contain both actual data & metadata
Can contain only element, only attributes or both
Is flexible; convenient for exchange data between different systems/platforms.

XML Fragment
Doesn't have a single root node

Root Node
Encloses all other elements within a xml document.
Example:
<Root>
    <Customer custid="1" contactname="Allen, Michael" />
    <Customer custid="2" contactname="Hassall, Mark" />
</Root>

XML Tags
Begin/start tag. Example <Employees>
End tag.            Example </Employees>

XML Element
The actual tags
Example: customer is an element name.
  <Customer>
      <custid>1</custid>
      <contactname>Allen, Michael</contactname>
  </Customer>
Note white space is not allowed in an element name. example: this is invalid
<custid   >1</custid>
Tag may contain data within the tags, these are attributes

Element Data
Data between the tags
Example: 
<Customer>John Doe</Customer>

Attribute data
The data inside of a xml element tag.
     Example:
     <Customers>
         <Customer custid="1" contactname="Allen, Michael" />
         <Customer custid="2" contactname="Hassall, Mark" />
     </Customers>
Attribute data must be enclosed with single or double quotes.
Attribute names must be unique inside an element tag .
Example: this is invalid since the 2 attribute names are the same
<Customer custid1='1' custid1='2' />
Attributes within an element form a set with no order.
Always parsed as text, not XML
Example: the &lt is interpret as '&lt' not < symbol
<Customer custid="&lt 7" />

Actual Data
The data itself

Metadata
Data about the actual data. Describe the data such as properties, relationship.


Reference: Microsoft 70-461 Training Kit

No comments:

Post a Comment