2 new revisions:

Revision: aeef53a2ad68
Author:   Pekka Klärck
Date:     Thu Jul  5 14:00:18 2012
Log: XML lib: Initial overall documentation. Not yet ready for review and k...
http://code.google.com/p/robotframework/source/detail?r=aeef53a2ad68

Revision: a761ce6e0170
Author:   Pekka Klärck
Date:     Thu Jul  5 14:00:25 2012
Log:      regen
http://code.google.com/p/robotframework/source/detail?r=a761ce6e0170

==============================================================================
Revision: aeef53a2ad68
Author:   Pekka Klärck
Date:     Thu Jul  5 14:00:18 2012
Log: XML lib: Initial overall documentation. Not yet ready for review and kw docs fully missing too.
http://code.google.com/p/robotframework/source/detail?r=aeef53a2ad68

Modified:
 /src/robot/libraries/XML.py

=======================================
--- /src/robot/libraries/XML.py Thu Jul  5 04:48:26 2012
+++ /src/robot/libraries/XML.py Thu Jul  5 14:00:18 2012
@@ -27,11 +27,172 @@


 class XML(object):
+    """Robot Framework test library for XML verification.
+
+ As the name implies, `XML` is a test library for verifying contents of XML + files. In practice this library is a pretty thin wrapper on top of Python's + [ElementTree XML API| http://docs.python.org/library/xml.etree.elementtree.html].
+
+    XML can be parsed into an element structure using either `Parse XML`,
+ `Get Element` or `Get Elements` keywords. The returned elements can then
+    be used as an input with all other keywords, but these keywords also
+    support parsing XML files and strings directly.
+
+    *Elements attributes*
+
+ All keywords returning elements, such as `Parse XML`, and `Get Element`,
+    return ElementTree's
+ [Element classes| http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element].
+    These elements can be used as inputs for other keywords, but they also
+    contain several useful attributes that can be accessed directly using
+    the extended variable syntax.
+
+    The attributes that are both useful and convenient to use in the test
+    data are explained below with examples. Also other attributes, and also
+    methods, can be accessed, but that is typically better to do in custom
+    libraries than directly in the test data.
+
+    In the examples `${XML}` and `${HTML}` refer to the following example
+    structures:
+
+    | <example>
+    |   <first>text</first>
+    |   <second id="2">
+    |     <child/>
+    |   </second>
+    |   <third>
+    |     <child>more text</child>
+    |     <second id="child"/>
+    |     <child><grandchild/></child>
+    |   </third>
+    | </example>
+
+    | <html>
+    |   <head><title>Example</title></head>
+    |   <body>
+    |     <p>
+    |       Example text with <b>bold</b> and <i>italics</i>.
+    |     </p>
+    |   </body>
+    | </html>
+
+    _tag_
+
+    The tag of the element.
+
+    | ${root} =       | Parse XML   | ${XML}  |
+    | Should Be Equal | ${root.tag} | example |
+
+    _text_
+
+ The text that the element contains or Python `None` if the element has no
+    text. Notice that the text _does not_ contain texts of possible child
+    elements nor text after/between children. Notice also that in XML
+ whitespace is significant, so the text contains also possible indentation
+    and newlines. To get also text of the possible children, optionally
+    whitespace normalized, use `Get Element Text` keyword.
+
+    | ${1st} =        | Get Element | ${XML}    | first  |
+    | Should Be Equal | ${1st.text} | text      |        |
+    | ${2nd} =        | Get Element | ${XML}    | second |
+    | Should Be Equal | ${2nd.text} | ${NONE}   |        |
+    | ${p} =          | Get Element | ${HTML}   | body/p |
+ | Should Be Equal | ${p.text} | \n${SPACE*6}Example text with${SPACE} |
+
+    _tail_
+
+ The text after the element before the next opening or closing tag. Python + `None` if the element has no tail. Similarly as with `text`, also `tail`
+    contains possible indentation and newlines.
+
+    | ${title} =      | Get Element    | ${HTML}   | head/title  |
+    | Should Be Equal | ${title.tail}  | ${NONE}   |             |
+    | ${b} =          | Get Element    | ${HTML}   | body/p/b    |
+    | Should Be Equal | ${b.tail}      | ${SPACE}and${SPACE}     |
+
+    _attrib_
+
+    A Python dictionary containing attributes of the element.
+
+    | ${1st} =        | Get Element         | ${XML} | first  |
+    | Should Be Empty | ${1st.attrib}       |        |        |
+    | ${2nd} =        | Get Element         | ${XML} | second |
+    | Should Be Equal | ${2nd.attrib['id']} | 2      |        |
+
+    *Finding elements with xpath*
+
+ ElementTree, and thus also this library, supports finding elements using + xpath expressions. ElementTree does not, however, support the full xpath + syntax, and what is supported depends on its version. ElementTree 1.3 that + is distributed with Python/Jython 2.7 supports richer syntax than versions
+    distributed with earlier Python interpreters.
+
+    Supported xpath syntax is explained below and
+    [ElementTree documentation|http://effbot.org/zone/element-xpath.htm]
+    provides more details. The examples use same `${XML}` and `${HTML}`
+    structures as earlier examples.
+
+    _Tag names_
+
+    When just a tag name is used, xpath matches all direct child elements
+    that have that tag name.
+
+    | ${elem} =        | Get Element   | ${XML}      | third  |
+    | Should Be Equal  | ${elem.tag}   | third       |        |
+    | @{children} =    | Get Elements  | ${elem}     | child  |
+    | Length Should Be | ${children}   | 2           |        |
+
+    _Paths_
+
+    Paths are creating by combining tag names with a forward slash (`/`).
+    For example, `parent/child` matches all `child` elements under `parent`
+    element.
+
+    | ${elem} = | Get Element | ${XML} | second/child            |
+    | ${elem} = | Get Element | ${XML} | third/child/grandchild  |
+
+    _Wildcards_
+
+    An asterisk (`*`) can be used in paths instead of a tag name to denote
+    any element.
+
+    | @{children} =    | Get Element | ${XML} | */child |
+    | Length Should Be | ${children} | 3      |         |
+
+    _Current node_
+
+    The current node is denoted with a dot (`.`). Normally the current node
+    is implicit and does not need to be included in the path.
+
+    _Search all sub elements_
+
+    Two forward slashes (`//`) mean that all sub elements, not only the
+ direct children, are searched. If the search is started from the current
+    element, an explicit dot is required.
+
+    | @{elements} =    | Get Element | ${XML} | .//second |
+    | Length Should Be | ${children} | 2      |           |
+
+    _Predicates_
+
+    Predicates allow selecting elements using also other criteria than tag
+ names such as attributes or position. They are specified after the normal
+    tag name or path using syntax `path[predicate]`.
+
+    Notice that predicates are supported only in ElementTree 1.3 that is
+    shipped with Python/Jython 2.7. What predicates are supported in that
+    version is explained in the table below.
+
+    | _Predicate_     | _Matches elements that_ | _Example_ |
+    | @attrib         | have the specified attribute. | third[@id] |
+ | @attrib="value" | have the specified attribute and it has the specified value. | *[@id="2"] | + | position | are in the specified position. Position can be an integer (starting from 1), expression `last()`, or relative expression like `last() - 1`. | third/child[1] | + | tag | have child element named `tag`. | third/child[grandchild] |
+
+    Predicates can also be stacked like `path[predicate1][predicate2]`.
+    A limitation is that possible position predicate must always be first.
     """
- Supported xpath is documented here: http://effbot.org/zone/element-xpath.htm
-    Notice that predicates (e.g. tag[@id="1"]) are supported only in ET 1.3
-    i.e in Python 2.7!
-    """
+
     _whitespace = re.compile('\s+')
     _xml_declaration = re.compile('^<\?xml .*\?>\n')


==============================================================================
Revision: a761ce6e0170
Author:   Pekka Klärck
Date:     Thu Jul  5 14:00:25 2012
Log:      regen
http://code.google.com/p/robotframework/source/detail?r=a761ce6e0170

Modified:
 /doc/libraries/XML.html

=======================================
--- /doc/libraries/XML.html     Thu Jun 28 14:48:38 2012
+++ /doc/libraries/XML.html     Thu Jul  5 14:00:25 2012
@@ -177,7 +177,7 @@
(function(a){var r=a.fn.domManip,d="_tmplitem",q=/^[^<]*(<[\w\W]+>)[^>]*$| \{\{\! /,b={},f={},e,p={key:0,data:{}},i=0,c=0,l=[];function g(g,d,h,e){var c={data:e||(e===0|| e===false)?e:d?d.data:{},_wrap:d?d._wrap:null,tmpl:null,parent:d|| null,nodes:[],calls:u,nest:w,wrap:x,html:v,update:t};g&&a.extend(c,g,{nodes:[],parent:d});if(h){c.tmpl=h;c._ctnt=c._ctnt| |c.tmpl(a,c);c.key=++i;(l.length?f:b)[i]=c}return c}a.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(f,d){a.fn[f]=function(n){var g=[],i=a(n),k,h,m,l,j=this.length===1&&this[0].parentNode;e=b|| {};if(j&&j.nodeType===11&&j.childNodes.length===1&&i.length===1){i[d](this[0]);g=this}else{for(h=0,m=i.length;h<m;h++){c=h;k=(h>0?this.clone(true):this).get();a(i[h])[d](k);g=g.concat(k)}c=0;g=this.pushStack(g,f,i.selector)}l=e;e=null;a.tmpl.complete(l);return g}});a.fn.extend({tmpl:function(d,c,b){return a.tmpl(this[0],d,c,b)},tmplItem:function(){return a.tmplItem(this[0])},template:function(b){return a.template(b,this[0])},domManip:function(d,m,k){if(d[0]&&a.isArray(d[0])){var g=a.makeArray(arguments),h=d[0],j=h.length,i=0,f;while(i<j&&!(f=a.data(h[i++],"tmplItem")));if(f&&c)g[2]=function(b){a.tmpl.afterManip(this,b,k)};r.apply(this,g)}else r.apply(this,arguments);c=0;!e&&a.tmpl.complete(b);return this}});a.extend({tmpl:function(d,h,e,c){var i,k=!c;if(k){c=p;d=a.template[d]||a.template(null,d);f={}}else if(!d){d=c.tmpl;b[c.key]=c;c.nodes=[];c.wrapped&&n(c,c.wrapped);return a(j(c,null,c.tmpl(a,c)))}if(!d)return[];if(typeof h==="function")h=h.call(c| |{});e&&e.wrapped&&n(e,e.wrapped);i=a.isArray(h)?a.map(h,function(a){return a?g(e,c,d,a):null}):[g(e,c,d,h)];return k?a(j(c,null,i)):i},tmplItem:function(b){var c;if(b instanceof a)b=b[0];while(b&&b.nodeType===1&&!(c=a.data(b,"tmplItem"))&&(b=b.parentNode));return c||p},template:function(c,b){if(b){if(typeof b==="string")b=o(b);else if(b instanceof a)b=b[0]||{};if(b.nodeType)b=a.data(b,"tmpl")|| a.data(b,"tmpl",o(b.innerHTML));return typeof c==="string"?(a.template[c]=b):b}return c?typeof c!=="string"?a.template(null,c):a.template[c]|| a.template(null,q.test(c)?c:a(c)):null},encode:function(a){return(""+a).split("&").join("&amp;").split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;")}});a.extend(a.tmpl,{tag:{tmpl:{_default:{$2:"null"},open:"if($notnull_1){__=__.concat($item.nest($1,$2));}"},wrap:{_default:{$2:"null"},open:"$item.calls(__,$1,$2);__=[];",close:"call=$item.calls();__=call._.concat($item.wrap(call,__));"},each:{_default:{$2:"$index, $value"},open:"if($notnull_1){$.each($1a,function($2){with(this){",close:"}});}"},"if":{open:"if(($notnull_1) && $1a){",close:"}"},"else":{_default:{$1:"true"},open:"}else if(($notnull_1) && $1a){"},html:{open:"if($notnull_1){__.push($1a);}"},"=":{_default:{$1:"$data"},open:"if($notnull_1){__.push($.encode($1a));}"},"!":{open:""}},complete:function(){b={}},afterManip:function(f,b,d){var e=b.nodeType===11?a.makeArray(b.childNodes):b.nodeType===1?[b]:[];d.call(f,b);m(e);c++}});function j(e,g,f){var b,c=f?a.map(f,function(a){return typeof a==="string"?e.key?a.replace(/(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g,"$1 "+d+'="'+e.key+'" $2'):a:j(a,e,a._ctnt)}):e;if(g)return c;c=c.join("");c.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,function(f,c,e,d){b=a(e).get();m(b);if(c)b=k(c).concat(b);if(d)b=b.concat(k(d))});return b?b:k(c)}function k(c){var b=document.createElement("div");b.innerHTML=c;return a.makeArray(b.childNodes)}function o(b){return new Function("jQuery","$item","var $=jQuery,call,__=[],$data=$item.data;with($data){__.push('"+a.trim(b).replace(/([\\'])/g,"\\$1").replace(/[\r\t\n]/g," ").replace(/\$\{([^\}]*)\}/g,"{{= $1}}").replace(/\{\{(\/?)(\w+|.)(?:\(((?:[^\}]| \}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]| \}(?!\}))*?)\))?\s*\}\}/g,function(m,l,k,g,b,c,d){var j=a.tmpl.tag[k],i,e,f;if(!j)throw"Unknown template tag: "+k;i=j._default|| [];if(c&&!/\w$/.test(b)){b+=c;c=""}if(b){b=h(b);d=d?","+h(d)+")":c?")":"";e=c?b.indexOf(".")>-1?b+h(c):"("+b+").call($item"+d:b;f=c?e:"(typeof("+b+")==='function'?("+b+").call($item):("+b+"))"}else f=e=i.$1| |"null";g=h(g);return"');"+j[l?"close":"open"].split("$notnull_1").join(b?"typeof("+b+")!=='undefined' && ("+b+")!=null":"true").split("$1a").join(f).split("$1").join(e).split("$2").join(g| |i.$2||"")+"__.push('"})+"');}return __;")}function n(c,b){c._wrap=j(c,true,a.isArray(b)?b:[q.test(b)?b:a(b).html()]).join("")}function h(a){return a?a.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null}function s(b){var a=document.createElement("div");a.appendChild(b.cloneNode(true));return a.innerHTML}function m(o){var n="_"+c,k,j,l={},e,p,h;for(e=0,p=o.length;e<p;e++){if((k=o[e]).nodeType!==1)continue;j=k.getElementsByTagName("*");for(h=j.length-1;h>=0;h--)m(j[h]);m(k)}function m(j){var p,h=j,k,e,m;if(m=j.getAttribute(d)){while(h.parentNode&&(h=h.parentNode).nodeType===1&&!(p=h.getAttribute(d)));if(p!==m){h=h.parentNode?h.nodeType===11?0:h.getAttribute(d)| |0:0;if(!(e=b[m])){e=f[m];e=g(e,b[h]|| f[h]);e.key=++i;b[i]=e}c&&o(m)}j.removeAttribute(d)}else if(c&&(e=a.data(j,"tmplItem"))){o(e.key);b[e.key]=e;h=a.data(j.parentNode,"tmplItem");h=h?h.key:0}if(e){k=e;while(k&&k.key!=h){k.nodes.push(j);k=k.parent}delete e._ctnt;delete e._wrap;a.data(j,"tmplItem",e)}function o(a){a=a+n;e=l[a]=l[a]||g(e,b[e.parent.key+n]||e.parent)}}}function u(a,d,c,b){if(!a)return l.pop();l.push({_:a,tmpl:d,item:this,data:c,options:b})}function w(d,c,b){return a.tmpl(a.template(d),c,b,this)}function x(b,d){var c=b.options||{};c.wrapped=d;return a.tmpl(a.template(b.tmpl),b.data,c,b.item)}function v(d,c){var b=this._wrap;return a.map(a(a.isArray(b)?b.join(""):b).filter(d| |"*"),function(a){return c?a.innerText||a.textContent:a.outerHTML|| s(a)})}function t(){var b=this.nodes;a.tmpl(null,null,null,this).insertBefore(b[0]);a(b).remove()}})(jQuery);
 </script>
 <script type="text/javascript">
-libdoc = {"doc":"<p>Supported xpath is documented here: <a href=\"http://effbot.org/zone/element-xpath.htm\";>http://effbot.org/zone/element-xpath.htm</a> Notice that support for predicates (e.g. tag[@id=\"1\"]) is supported only in 1.3 i.e in Python 2.7!</p>","generated":"2012-06-29 00:47:14","inits":[],"keywords":[{"args":"source, name, expected, xpath=., message=None","doc":"","name":"Element Attribute Should Be","shortdoc":""},{"args":"source, name, pattern, xpath=., message=None","doc":"","name":"Element Attribute Should Match","shortdoc":""},{"args":"source, expected, xpath=., normalize_whitespace=False, message=None","doc":"","name":"Element Text Should Be","shortdoc":""},{"args":"source, pattern, xpath=., normalize_whitespace=False, message=None","doc":"","name":"Element Text Should Match","shortdoc":""},{"args":"source","doc":"","name":"Element To String","shortdoc":""},{"args":"source, expected, normalize_whitespace=False","doc":"","name":"Elements Should Be Equal","shortdoc":""},{"args":"source, expected, normalize_whitespace=False, message=None","doc":"","name":"Elements Should Match","shortdoc":""},{"args":"source, xpath=.","doc":"","name":"Get Element","shortdoc":""},{"args":"source, name, xpath=., default=None","doc":"","name":"Get Element Attribute","shortdoc":""},{"args":"source, xpath=.","doc":"","name":"Get Element Attributes","shortdoc":""},{"args":"source, xpath=., normalize_whitespace=False","doc":"","name":"Get Element Text","shortdoc":""},{"args":"source, xpath","doc":"","name":"Get Elements","shortdoc":""},{"args":"source, xpath, normalize_whitespace=False","doc":"","name":"Get Elements Texts","shortdoc":""},{"args":"source","doc":"","name":"Log Element","shortdoc":""},{"args":"source","doc":"","name":"Parse Xml","shortdoc":""}],"name":"XML","named_args":true,"scope":"test case","version":"<unknown>"}; +libdoc = {"doc":"<p>Robot Framework test library for XML verification.</p>\n<p>As the name implies, <span class=\"name\">XML</span> is a test library for verifying contents of XML files. In practice this library is a pretty thin wrapper on top of Python's <a href=\"ElementTree XML API\">http://docs.python.org/library/xml.etree.elementtree.html</a>.</p>\n<p>XML can be parsed into an element structure using either <a href=\"#Parse Xml\" class=\"name\">Parse XML</a>, <a href=\"#Get Element\" class=\"name\">Get Element</a> or <a href=\"#Get Elements\" class=\"name\">Get Elements</a> keywords. The returned elements can then be used as an input with all other keywords, but these keywords also support parsing XML files and strings directly.</p>\n<p><b>Elements attributes</b></p>\n<p>All keywords returning elements, such as <a href=\"#Parse Xml\" class=\"name\">Parse XML</a>, and <a href=\"#Get Element\" class=\"name\">Get Element</a>, return ElementTree's <a href=\"Element classes\">http://docs.python.org/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element</a>. These elements can be used as inputs for other keywords, but they also contain several useful attributes that can be accessed directly using the extended variable syntax.</p>\n<p>The attributes that are both useful and convenient to use in the test data are explained below with examples. Also other attributes, and also methods, can be accessed, but that is typically better to do in custom libraries than directly in the test data.</p>\n<p>In the examples <span class=\"name\">${XML}</span> and <span class=\"name\">${HTML}</span> refer to the following example structures:</p>\n<pre>\n&lt;example&gt;\n &lt;first&gt;text&lt;/first&gt;\n &lt;second id=\"2\"&gt;\n &lt;child/&gt;\n &lt;/second&gt;\n &lt;third&gt;\n &lt;child&gt;more text&lt;/child&gt;\n &lt;second id=\"child\"/&gt;\n &lt;child&gt;&lt;grandchild/&gt;&lt;/child&gt;\n &lt;/third&gt;\n&lt;/example&gt;\n</pre>\n<pre>\n&lt;html&gt;\n &lt;head&gt;&lt;title&gt;Example&lt;/title&gt;&lt;/head&gt;\n &lt;body&gt;\n &lt;p&gt;\n Example text with &lt;b&gt;bold&lt;/b&gt; and &lt;i&gt;italics&lt;/i&gt;.\n &lt;/p&gt;\n &lt;/body&gt;\n&lt;/html&gt;\n</pre>\n<p><i>tag</i></p>\n<p>The tag of the element.</p>\n<table border=\"1\">\n<tr>\n<td>${root} =</td>\n<td>Parse XML</td>\n<td>${XML}</td>\n</tr>\n<tr>\n<td>Should Be Equal</td>\n<td>${root.tag}</td>\n<td>example</td>\n</tr>\n</table>\n<p><i>text</i></p>\n<p>The text that the element contains or Python <span class=\"name\">None</span> if the element has no text. Notice that the text <i>does not</i> contain texts of possible child elements nor text after/between children. Notice also that in XML whitespace is significant, so the text contains also possible indentation and newlines. To get also text of the possible children, optionally whitespace normalized, use <a href=\"#Get Element Text\" class=\"name\">Get Element Text</a> keyword.</p>\n<table border=\"1\">\n<tr>\n<td>${1st} =</td>\n<td>Get Element</td>\n<td>${XML}</td>\n<td>first</td>\n</tr>\n<tr>\n<td>Should Be Equal</td>\n<td>${1st.text}</td>\n<td>text</td>\n<td></td>\n</tr>\n<tr>\n<td>${2nd} =</td>\n<td>Get Element</td>\n<td>${XML}</td>\n<td>second</td>\n</tr>\n<tr>\n<td>Should Be Equal</td>\n<td>${2nd.text}</td>\n<td>${NONE}</td>\n<td></td>\n</tr>\n<tr>\n<td>${p} =</td>\n<td>Get Element</td>\n<td>${HTML}</td>\n<td>body/p</td>\n</tr>\n<tr>\n<td>Should Be Equal</td>\n<td>${p.text}</td>\n<td></td>\n<td></td>\n</tr>\n</table>\n<p>${SPACE*6}Example text with${SPACE} |</p>\n<p><i>tail</i></p>\n<p>The text after the element before the next opening or closing tag. Python <span class=\"name\">None</span> if the element has no tail. Similarly as with <span class=\"name\">text</span>, also <span class=\"name\">tail</span> contains possible indentation and newlines.</p>\n<table border=\"1\">\n<tr>\n<td>${title} =</td>\n<td>Get Element</td>\n<td>${HTML}</td>\n<td>head/title</td>\n</tr>\n<tr>\n<td>Should Be Equal</td>\n<td>${title.tail}</td>\n<td>${NONE}</td>\n<td></td>\n</tr>\n<tr>\n<td>${b} =</td>\n<td>Get Element</td>\n<td>${HTML}</td>\n<td>body/p/b</td>\n</tr>\n<tr>\n<td>Should Be Equal</td>\n<td>${b.tail}</td>\n<td>${SPACE}and${SPACE}</td>\n<td></td>\n</tr>\n</table>\n<p><i>attrib</i></p>\n<p>A Python dictionary containing attributes of the element.</p>\n<table border=\"1\">\n<tr>\n<td>${1st} =</td>\n<td>Get Element</td>\n<td>${XML}</td>\n<td>first</td>\n</tr>\n<tr>\n<td>Should Be Empty</td>\n<td>${1st.attrib}</td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>${2nd} =</td>\n<td>Get Element</td>\n<td>${XML}</td>\n<td>second</td>\n</tr>\n<tr>\n<td>Should Be Equal</td>\n<td>${2nd.attrib['id']}</td>\n<td>2</td>\n<td></td>\n</tr>\n</table>\n<p><b>Finding elements with xpath</b></p>\n<p>ElementTree, and thus also this library, supports finding elements using xpath expressions. ElementTree does not, however, support the full xpath syntax, and what is supported depends on its version. ElementTree 1.3 that is distributed with Python/Jython 2.7 supports richer syntax than versions distributed with earlier Python interpreters.</p>\n<p>Supported xpath syntax is explained below and <a href=\"ElementTree documentation\">http://effbot.org/zone/element-xpath.htm</a> provides more details. The examples use same <span class=\"name\">${XML}</span> and <span class=\"name\">${HTML}</span> structures as earlier examples.</p>\n<p><i>Tag names</i></p>\n<p>When just a tag name is used, xpath matches all direct child elements that have that tag name.</p>\n<table border=\"1\">\n<tr>\n<td>${elem} =</td>\n<td>Get Element</td>\n<td>${XML}</td>\n<td>third</td>\n</tr>\n<tr>\n<td>Should Be Equal</td>\n<td>${elem.tag}</td>\n<td>third</td>\n<td></td>\n</tr>\n<tr>\n<td>@{children} =</td>\n<td>Get Elements</td>\n<td>${elem}</td>\n<td>child</td>\n</tr>\n<tr>\n<td>Length Should Be</td>\n<td>${children}</td>\n<td>2</td>\n<td></td>\n</tr>\n</table>\n<p><i>Paths</i></p>\n<p>Paths are creating by combining tag names with a forward slash (<span class=\"name\">/</span>). For example, <span class=\"name\">parent/child</span> matches all <span class=\"name\">child</span> elements under <span class=\"name\">parent</span> element.</p>\n<table border=\"1\">\n<tr>\n<td>${elem} =</td>\n<td>Get Element</td>\n<td>${XML}</td>\n<td>second/child</td>\n</tr>\n<tr>\n<td>${elem} =</td>\n<td>Get Element</td>\n<td>${XML}</td>\n<td>third/child/grandchild</td>\n</tr>\n</table>\n<p><i>Wildcards</i></p>\n<p>An asterisk (<span class=\"name\">*</span>) can be used in paths instead of a tag name to denote any element.</p>\n<table border=\"1\">\n<tr>\n<td>@{children} =</td>\n<td>Get Element</td>\n<td>${XML}</td>\n<td>*/child</td>\n</tr>\n<tr>\n<td>Length Should Be</td>\n<td>${children}</td>\n<td>3</td>\n<td></td>\n</tr>\n</table>\n<p><i>Current node</i></p>\n<p>The current node is denoted with a dot (<span class=\"name\">.</span>). Normally the current node is implicit and does not need to be included in the path.</p>\n<p><i>Search all sub elements</i></p>\n<p>Two forward slashes (<span class=\"name\">//</span>) mean that all sub elements, not only the direct children, are searched. If the search is started from the current element, an explicit dot is required.</p>\n<table border=\"1\">\n<tr>\n<td>@{elements} =</td>\n<td>Get Element</td>\n<td>${XML}</td>\n<td>.//second</td>\n</tr>\n<tr>\n<td>Length Should Be</td>\n<td>${children}</td>\n<td>2</td>\n<td></td>\n</tr>\n</table>\n<p><i>Predicates</i></p>\n<p>Predicates allow selecting elements using also other criteria than tag names such as attributes or position. They are specified after the normal tag name or path using syntax <span class=\"name\">path[predicate]</span>.</p>\n<p>Notice that predicates are supported only in ElementTree 1.3 that is shipped with Python/Jython 2.7. What predicates are supported in that version is explained in the table below.</p>\n<table border=\"1\">\n<tr>\n<td><i>Predicate</i></td>\n<td><i>Matches elements that</i></td>\n<td><i>Example</i></td>\n</tr>\n<tr>\n<td>@attrib</td>\n<td>have the specified attribute.</td>\n<td>third[@id]</td>\n</tr>\n<tr>\n<td>@attrib=\"value\"</td>\n<td>have the specified attribute and it has the specified value.</td>\n<td>*[@id=\"2\"]</td>\n</tr>\n<tr>\n<td>position</td>\n<td>are in the specified position. Position can be an integer (starting from 1), expression <span class=\"name\">last()</span>, or relative expression like <span class=\"name\">last() - 1</span>.</td>\n<td>third/child[1]</td>\n</tr>\n<tr>\n<td>tag</td>\n<td>have child element named <span class=\"name\">tag</span>.</td>\n<td>third/child[grandchild]</td>\n</tr>\n</table>\n<p>Predicates can also be stacked like <span class=\"name\">path[predicate1][predicate2]</span>. A limitation is that possible position predicate must always be first.</p>","generated":"2012-07-05 23:58:23","inits":[],"keywords":[{"args":"source, name, expected, xpath=., message=None","doc":"","name":"Element Attribute Should Be","shortdoc":""},{"args":"source, name, pattern, xpath=., message=None","doc":"","name":"Element Attribute Should Match","shortdoc":""},{"args":"source, expected, xpath=., normalize_whitespace=False, message=None","doc":"","name":"Element Text Should Be","shortdoc":""},{"args":"source, pattern, xpath=., normalize_whitespace=False, message=None","doc":"","name":"Element Text Should Match","shortdoc":""},{"args":"source","doc":"","name":"Element To String","shortdoc":""},{"args":"source, expected, normalize_whitespace=False","doc":"","name":"Elements Should Be Equal","shortdoc":""},{"args":"source, expected, normalize_whitespace=False","doc":"","name":"Elements Should Match","shortdoc":""},{"args":"source, xpath=.","doc":"","name":"Get Child Elements","shortdoc":""},{"args":"source, xpath=.","doc":"","name":"Get Element","shortdoc":""},{"args":"source, name, xpath=., default=None","doc":"","name":"Get Element Attribute","shortdoc":""},{"args":"source, xpath=.","doc":"","name":"Get Element Attributes","shortdoc":""},{"args":"source, xpath=., normalize_whitespace=False","doc":"","name":"Get Element Text","shortdoc":""},{"args":"source, xpath","doc":"","name":"Get Elements","shortdoc":""},{"args":"source, xpath, normalize_whitespace=False","doc":"","name":"Get Elements Texts","shortdoc":""},{"args":"source, level=INFO","doc":"","name":"Log Element","shortdoc":""},{"args":"source","doc":"","name":"Parse Xml","shortdoc":""}],"name":"XML","named_args":true,"scope":"test case","version":"<unknown>"};
 </script>
 <title></title>
 </head>

Reply via email to