Return to doc.sitecore.com

1.  Data Structure
Prev Next

In XML, data structure and content are represented as a node tree containing elements with attributes and descendants.  Markup is similar to that used for HTML but enforces at least the following rules:

While most access to the XML repository should be through APIs and XSL extensions, attributes are commonly accessed directly and an understanding of the generic structure can sometimes be helpful. 

Sitecore's XML structure is composed of only five element types – item, version, fields, field and content – and is therefore infinitely flexible.  Every Item in the content structure is represented by an item element which may have any number of versions.  Each version contains a fields element which may contain any number of field elements which represent the data of the Item.  Each field contains a content element which contains the field contents.

Sitecore’s implementation of XML is relatively straightforward, consisting mainly of elements, attributes and text, where most elements contain nested elements.  In the following simplified example, most of the attributes and repeating elements have been omitted for demonstrative purposes.

1.1.  Sample Sitecore XML

<item key="home">
  
<version language="en" version="1">
    
<fields>
      
<field key="title">
        
<content>Home Page</content>
      
</field>
    
</fields>
  
</version>
  
<item key="child">
    
<version language="en" version="1">
      
<fields>
        
<field key="title">
          
<content>Child Page</content>
        
</field>
      
</fields>
    
</version>
  
</item>
</item>

1.2.  Sample XML Description

Every element is wrapped in angle braces (“<>”).  Within each element a number of attributes may be defined; each attribute has a key (before the “=” character) and value (within the quotes).  Most elements contain nested elements, for instance each field element contains a content element.  Each content element in this example contains text, though for some types of fields such as Image a content element may contain an XML element with attributes.

The root element of the Sitecore XML tree is <item key="sitecore">.  There are at least two ways to refer to this node in XPath – explicitly (/item[@key='sitecore']) or shorthand (/*).  The first slash character instructs the XPath engine to navigate to the root of the document, and the first example locates all root-level element with its key attribute set to the value “sitecore”.  Since there is only one root-level element in any valid XML document, the second example performs the same function by navigating to the root of the document and matching any element at that level.

In Some cases Sitecore supports a shorthand notation for indexing into the XML document, allowing /item[@key='sitecore'] to be specified as simply /sitecore.  This notation cannot be used in XSL.

Any item element may contain any number of item elements recursively nested to any level.  Each second-level item (under /sitecore) is visible in the first step of the treecrumb in Content Editor.  For instance, /sitecore/content (<item key="sitecore"><item key="content">) is the default selection in the treecrumb, representing the Content section of Sitecore.  Additional second-level nodes include /sitecore/media library, /sitecore/masters, /sitecore/layout and /sitecore/system.

Only nodes in the Content area are typically considered Items, and most nodes built from custom Templates are created under Content.  This tree can be indexed to any depth using XPath, for example to get the home page of the site /sites/Custom one XPath would be /*/item[@key='content']/item[@key='sites']/item[@key='custom'] (shorthand: /sitecore/content/sites/custom).

1.3.  Sitecore Item Elements

Each item element has the following attributes:

Attribute:

Value:

@template

Lowercase name of Template associated with node.

@id

GUID of node.

@name

Name of node (typically text which appears in user interface).

@key

Lowercase @name.

@sortorder

Numeric sort order applied by a user manually or through UI sorting.

@tid

GUID of the Template associated with this Item.

@mid

GUID of the Master associated with this Item.

@created

Creation ISO date (“yyyyMMddTHHmmss”)

@createdby

Username of creator.

@updatedby

Username of last updater.

@parentid

GUID of parent node.

 

Elements of type item may only have child nodes of type version and item, where version elements represent versions of the item and item elements represent children of the item.

1.4.  Sitecore Version Elements

Elements of type version always have two attributes – language and version, where language is the value of the ISO field in the corresponding Language Item under /system/Languages and version is the Sitecore version identifier for the data.

1.5.  Sitecore Fields Elements

Each version element contains a fields element with no attributes which servers as a container for multiple field elements.

1.6.  Sitecore Field Elements

Each field element has the following attributes:

Attribute:

Value:

@tfid

GUID of templating field associated with this data field.

@key

Key of field (lowercase of field name).

@type

Data type of field.

 

Each field contains a content element with no attributes which contains the data entered into the field.  Data for more field types is stored as text, though some field types such as Image and Link store data as XML.

A simplified example with most field elements removed and actual GUIDs replaced with {GUID} follows.

1.7.  Sample XML with Fields

<item name="Home" key="home" id="{GUID}" tid="{GUID}" mid="{GUID}"
      sortorder
="10" template="{templatekey}">
  
<version language="da" version="1">
    
<fields>
      
<field tfid="{GUID}" key="title" type="html">
        
<content>{Danish title}</content>
      
</field>
    
</fields>
  
</version>
  
<version language="en" version="1">
    
<fields>
      
<field tfid="{GUID}" key="text" type="html">
        
<content>{English title}</content>
      
</field>
    
</fields>
  
</version>
  
<item name="Child" key="child" id="{GUID}" tid="{GUID}" mid="{GUID}"
        sortorder
="" template="{templatekey}">
    
<version language="da" version="1">
      
<fields>
        
<field tfid="{GUID}" key="title" type="html">
          
<content>{Danish title}</content>
        
</field>
    
</fields>
    
</version>
    
<version language="en" version="1">
      
<fields>
        
<field tfid="{GUID}" key="text" type="html">
          
<content>{English title}</content>
        
</field>
      
</fields>
    
</version>

1.8.  Sitecore XML Flavors

Sitecore has two kinds of item XML representations, or flavors if you will.

Serializer XML is the heavyweight format, containing everything Sitecore needs to know to get the item from one solution and paste into others: all attributes, field values in all versions and languages. It is used by the packager.

To get serializer xml programmatically:

item.GetOuterXml(deep);

XSLT XML is the internal interpretation that is fed to XSL renderings (tranformations). This is the lightweight brother, containing only item attributes and field ids. No field values, only the current version and language. You would want to know how it looks like if you code XSL renderings.

To get XSLT xml programmatically:

ItemNavigator navigator = Factory.CreateItemNavigator(rootItem);
writer.Write(navigator.OuterXml);


Prev Next