| 1 | = How do I read XML Paths with Rappture1.x? = |
| 2 | |
| 3 | Rappture uses a very simple, clear method for refering to elements |
| 4 | of an xml tree. Take this node for example: |
| 5 | |
| 6 | {{{ |
| 7 | <run> |
| 8 | <input> |
| 9 | <number id="temperature"> |
| 10 | <default>10</default> |
| 11 | <current>15</current> |
| 12 | </number> |
| 13 | </input> |
| 14 | </run> |
| 15 | }}} |
| 16 | |
| 17 | In the above example, there are 4 accessible xml nodes. |
| 18 | 1. input |
| 19 | 2. number |
| 20 | 3. default |
| 21 | 4. current |
| 22 | |
| 23 | <run> is not considered an accessible node for Rappture. |
| 24 | Instead it is named the root node. All xml information |
| 25 | relevant to Rappture can be found inside of the root node's |
| 26 | <run>...</run> tags. |
| 27 | |
| 28 | In general all accessible nodes are named using the following scheme: |
| 29 | {{{ |
| 30 | nodeType(nodeId) |
| 31 | }}} |
| 32 | |
| 33 | nodeType refers to the type of node, or the text found between '<' and '>'. |
| 34 | nodeId refers to the id attribute within the opening node tag. |
| 35 | In the first example, the different nodeTypes are input, number, default, |
| 36 | and current. Only one node has a nodeId, that is the number node. Since the |
| 37 | input tag has no nodeId, its xml path (relative to the root node) is: |
| 38 | |
| 39 | {{{ |
| 40 | input |
| 41 | }}} |
| 42 | |
| 43 | In the first example the number node can be referred to using three |
| 44 | different names |
| 45 | |
| 46 | {{{ |
| 47 | input.number |
| 48 | input.number(temperature) |
| 49 | input.(temperature) |
| 50 | }}} |
| 51 | |
| 52 | The first way of referring to the number node simply joins two node names |
| 53 | together. The second way reflects a stricter naming convention which |
| 54 | encompasses full names for all nodes. The full name for the input nodes is |
| 55 | 'input' and the full name for the number node is 'number(temperature)'. |
| 56 | The third name is a bit trickier to decompose. 'input' is the nodeType of the |
| 57 | parent node, but the nodeType of the child node is not provided. This is |
| 58 | acceptable. As a short cut, if the nodeId is provided within parenthesis, |
| 59 | it can still be searched for. |
| 60 | |
| 61 | Note that the best way to refer to a node is to use its full name. There |
| 62 | would be no guarantee the correct node will be found if without using |
| 63 | the full name if the xml looked like this: |
| 64 | {{{ |
| 65 | <run> |
| 66 | <input> |
| 67 | <number id="temperature"> |
| 68 | <default>10</default> |
| 69 | <current>15</current> |
| 70 | </number> |
| 71 | <number id="Ef"> |
| 72 | <default>3</default> |
| 73 | <current>2</current> |
| 74 | </number> |
| 75 | |
| 76 | </input> |
| 77 | </run> |
| 78 | }}} |
| 79 | |
| 80 | In this case, just saying 'input.number' would return the first instance |
| 81 | of the node of type 'number' under the parent node 'input'. A more appropriate |
| 82 | way of referring to each of these nodes would be: |
| 83 | |
| 84 | {{{ |
| 85 | input.number(temperature) |
| 86 | input.number(Ef) |
| 87 | }}} |
| 88 | |
| 89 | Similarly the default and current tags can be referred to using the following names: |
| 90 | {{{ |
| 91 | input.number(temperature).default |
| 92 | input.number(temperature).current |
| 93 | }}} |
| 94 | |
| 95 | [wiki:FAQ Back to Frequently Asked Questions] |