Re: Counting Elements in an xml file



On Aug 30, 2:17 pm, Paul Boddie <p...@xxxxxxxxxxxxx> wrote:
On 30 Aug, 19:37, Ouray Viney <ovi...@xxxxxxxxx> wrote:



<Testcase execute="true" name="foobar">

I would like to be able to count the number of TestCases that contain
the "execute=true" but not the ones that contain "execute=false".

With XPath-capable libraries, it should be enough to execute an XPath
query on the document. For example:

  import libxml2dom
  d = libxml2dom.parse(filename)
  number_of_cases = d.xpath("count(//Testcase[@execute='true'])")

This applies the XPath count function to all Testcase elements in the
document having an execute attribute with a value of 'true', thus
returning the number of matching elements.

Paul

Hi All:

Thank you very much for all your valuable input. All the examples
provided are exactly what I need to get started.

Enjoy the long weekend (for those in North America).

Cheers
.



Relevant Pages

  • Re: Counting Elements in an xml file
    ... I would like to be able to count the number of TestCases that contain ... With XPath-capable libraries, it should be enough to execute an XPath ... This applies the XPath count function to all Testcase elements in the ...
    (comp.lang.python)
  • Re: TKinter, buttonwidget response problem(1) and all btns the same size(2)!
    ...     def CreateWidgets: ... That code tells python to execute the Display function and assign the ... function's return value to the variable command. ...
    (comp.lang.python)
  • Re: A Range of Interesting German Devices of WW2
    ...    http://www.historyplace.com/worldwar2/timeline/malmedy.htm ... STAGED BY JEWS!! ... highest honor and caliber, would never execute anyone... ...
    (rec.aviation.military)
  • Re: Error - Please Help
    ... I am getting an error when I execute a procedure:- ...   COMMIT; ... See SQLNET.LOG to find secondary error if not provided ...
    (comp.databases.oracle.server)
  • Re: How does an ALU work?
    ... On 14 May, 11:26, "Piotr Wyderski" ... order to execute that many *different* instructions in a single cycle? ... I presume it's not a one big MUX + a bunch of sub-ALUs designed ...     Best regards ...
    (comp.arch)