XML Terminology

This page uses the  XML terms and concepts used in the guide.

DOM
The DOM defines the logical structure of documents and the way a document is accessed and manipulated.

The DOM presents an XML document as a tree structure.

Node
Everything in an XML document is a node. For example, the entire document is the document node, and every element is an element node.

Root node
The topmost node of a tree. In the case of XML documents, it is always the document node, and not the top-most element.

Parent node
An immediate ascendant of another node. The root node is the parent of all other nodes in the document.

Child node
An immediate descendant of another node. Note that element attributes are not generally considered child elements.

About the XML document in this section

The examples in this section use the following XML document:

<book>
  <title>Test Book</title>
  <chapter>
    <title>Ch1</title>
    <para>p1.1</para>
    <para>p1.2</para>
    <para>p1.3</para>
  </chapter>
  <chapter>
    <title>C </title>
    <para>p2.1</para>
    <para>p2.2</para>
  </chapter>
</book>  

The node tree of this document is:

document
 |
 +- element book
     |
     +- text "\n  "
     |
     +- element title
     |   |
     |   +- text "Test Book"
     |
     +- text "\n  "
     |
     +- element chapter
     |   |
     |   +- text "\n    "
     |   |
     |   +- element title
     |   |   |
     |   |   +- text "Ch1"
     |   |
     |   +- text "\n    "
     |   |
     |   +- element para     
     |   |   |
     |   |   +- text "p1.1"
     |   |
     |   +- text "\n    "
     |   |
     |   +- element para     
     |   |   |
     |   |   +- text "p1.2"
     |   |
     |   +- text "\n    "
     |   |
     |   +- element para     
     |      |
     |      +- text "p1.3"
     |
     +- element
         |
         +- text "\n    "
         |
         +- element title
         |   |
         |   +- text "C "
         |
         +- text "\n    "
         |
         +- element para     
         |   |
         |   +- text "p2.1"
         |
         +- text "\n    "
         |
         +- element para     
             |
             +- text "p2.2"  

Note that the "\n  "-s are the line breaks (indicated here with \n, an escape sequence used in RPL string literals) and the indentation spaces between the tags.

Putting the XML into the data model

If a string with the XML is provided in the example in a variable xml, you can execute the following RPL code to create a node:

<#assign doc=parsexml(xml)>

This will create the data node doc.

Alternately, you can enter the above XML in multiple lines and with concatenation as:

<#assign doc=parsexml(
'<book>' +
'  <title>Test Book</title>' +
'  <chapter>' +
'    <title>Ch1</title>' +
'    <para>p1.1</para>' +
'    <para>p1.2</para>' +
'    <para>p1.3</para>' +
'  </chapter>' +
'  <chapter>' +
'    <title>C </title>' +
'    <para>p2.1</para>' +
'    <para>p2.2</para>' +
'  </chapter>' +
'</book>')>  

You can also store an XML file in the Content Library, then load it into the data model as follows:

<#assign doc=parsexml(load("cms://contentlibrary/books/book.xml"))>

You can download content from an external site by loading the content from a web server as follows:

<#assign doc=parsexml(load("http://www.example.com/books/book.xml"))>

NOTE: To be able to download from http or https, your account must be enabled by your Responsys representative.

In general, the source of the XML string can come from any variable. It is common practice to enter XML as part of dynamic variables, but in some instances the XML can come from database fields or from other string constants.

You can provide the XML directly as field of your contact list, and load it as follows:

<#assign doc=parsexml(profile.purchases)>

We do not recommend this practice because it might increase the size of your database if the record's XML becomes large.

Next steps

Working with imperative XML processing