Python-Ref > XML > DOM > Getting value from attributes
 
 

<-^^->
Klíčová slova
Moduly
Knihovní funkce

Getting value from attributes

Expand/Shrink
<examples>
  <example num="1">
    <title>Example 1</title>
    <text>This is example nr. 1. It shows how an example looks.</text>
  </example>

  <example num="2">
    <title>Example 2</title>
    <text>Another example. Imagine some ingenious text here...</text>
  </example>
</examples>
Zdroj: (dom8-1.py)
  1   import xml.dom.minidom as dom
  2   
  3   doc = dom.parse( "example.xml")
  4   
  5   for example_element in doc.getElementsByTagName( "example"):
  6       print "@num =", example_element.getAttribute( "num")
stdout:
@num = 1
@num = 2
Doba běhu: 49.4 ms