wiki:FAQ_XmlPathNames

Version 1 (modified by dkearney, 18 years ago) (diff)

--

How do I read XML Paths with Rappture1.x?

Rappture uses a very simple, clear method for refering to elements of an xml tree. Take this node for example:

<run>
    <input>
        <number id="temperature">
            <default>10</default>
            <current>15</current>
        </number>
    </input>
</run>

In the above example, there are 4 accessible xml nodes.

  1. input
  2. number
  3. default
  4. current

<run> is not considered an accessible node for Rappture. Instead it is named the root node. All xml information relevant to Rappture can be found inside of the root node's <run>...</run> tags.

In general all accessible nodes are named using the following scheme:

nodeType(nodeId)

nodeType refers to the type of node, or the text found between '<' and '>'. nodeId refers to the id attribute within the opening node tag. In the first example, the different nodeTypes are input, number, default, and current. Only one node has a nodeId, that is the number node. Since the input tag has no nodeId, its xml path (relative to the root node) is:

input

In the first example the number node can be referred to using three different names

input.number
input.number(temperature)
input.(temperature)

The first way of referring to the number node simply joins two node names together. The second way reflects a stricter naming convention which encompasses full names for all nodes. The full name for the input nodes is 'input' and the full name for the number node is 'number(temperature)'. The third name is a bit trickier to decompose. 'input' is the nodeType of the parent node, but the nodeType of the child node is not provided. This is acceptable. As a short cut, if the nodeId is provided within parenthesis, it can still be searched for.

Note that the best way to refer to a node is to use its full name. There would be no guarantee the correct node will be found if without using the full name if the xml looked like this:

<run>
    <input>
        <number id="temperature">
            <default>10</default>
            <current>15</current>
        </number>
        <number id="Ef">
            <default>3</default>
            <current>2</current>
        </number>

    </input>
</run>

In this case, just saying 'input.number' would return the first instance of the node of type 'number' under the parent node 'input'. A more appropriate way of referring to each of these nodes would be:

input.number(temperature)
input.number(Ef)

Similarly the default and current tags can be referred to using the following names:

input.number(temperature).default
input.number(temperature).current

Back to Frequently Asked Questions