Tutorial 3: Node Referencing & Alternative Parsers

by Tom Byrne 13. May 2010 08:47

This is part three of a three part tutorial.

  1. Node References
  2. Configuring SiteStream URLs
  3. Download Source

1. Node References

SiteStream XML allows you to have references between objects that will be resolved when parent item is resolved.

This can help in:

  • Reducing the amount of XML and processing by listing common objects once and referencing them multiple times.
  • Help create complex relationships between objects that would otherwise require lengthy coding.

The syntax used to reference other nodes is:

childObject="{root/item2}"

Where 'childObject' is the name of the property this reference will fill.

Or, if it is preferrable to use a node to reference:

<String id="childObject">{root/item2}</String>

References do not need to remain within their own XML file/source and can reference items anywhere in all of your linked XML sources.

To expand on the example in part 1, I will add a reference to item2 which will result in item2's 'childObject' object being pointed to item3.

myXML.xml:

<Array id="root"
myPackage="myPackage.*">
<myPackage:MyClass id="item1"/>
<myPackage:MyClass id="item2" childObject="{root/item3}"/>
<myPackage:MyClass id="item3"/>
<myPackage:MyClass id="item4"/>
<myPackage:MyClass id="item5"/>
</Array>

Currently SiteStream only allows for absolute paths in Node References, meaning that if an XML file's position relative to the root changes, so to must any references pointing into it (including those within the file itself).

 

2. Alternative Parsers

The rules and methods SiteStream uses to parse XML can be modified on a per item basis. This is done by having an item (created in your XML) implement the ISiteStreamItem interface, this will then allow full control over how this item (and it's descendants) are parsed.

Note that the item itself will be created with it's parents settings (or the default settings if no ancestor was an ISiteStreamItem), as SiteStream doesn't know if it is an ISiteStreamItem until after it is created. All subsequent properties and children will then be parsed with the newly created object.

This feature has most commonly been used to create collections of items which only get resolved when they are specifically requested (as opposed to their parent object), which can be very useful for creating libraries of objects.

 

3. Download Source

 

< Goto Tutorial 2

Tags:
Categories:

Comments

5/13/2010 10:19:11 AM #

Tutorial 2: Managing XML/SWF payloads easily

Tutorial 2: Managing XML/SWF payloads easily

FARMCode.org