1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886
|
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=us-ascii' />
<title>The elementtree.ElementTree Module</title>
<link rel='stylesheet' href='effbot.css' type='text/css' />
</head>
<body>
<h1>The elementtree.ElementTree Module</h1>
<p>The <b>Element</b> type is a flexible container object, designed to
store hierarchical data structures in memory. The type can be
described as a cross between a list and a dictionary.
</p><p>
Each element has a number of properties associated with it:
<ul>
<li>a <i>tag</i>. This is a string identifying what kind of data
this element represents (the element type, in other words).</li>
<li>a number of <i>attributes</i>, stored in a Python dictionary.</li>
<li>a <i>text</i> string.</li>
<li>an optional <i>tail</i> string.</li>
<li>a number of <i>child elements</i>, stored in a Python sequence</li>
</ul>
To create an element instance, use the <a class="link" href="#elementtree.ElementTree.Element-function"><b>Element</b></a> or <a class="link" href="#elementtree.ElementTree.SubElement-function"><b>SubElement</b></a> factory functions.
</p><p>
The <a class="link" href="#elementtree.ElementTree.ElementTree-class"><b>ElementTree</b></a> class can be used to wrap an element
structure, and convert it from and to XML.
</p><h2>Module Contents</h2>
<dl>
<dt><b>_ElementInterface(tag, attrib)</b> (class) [<a href='#elementtree.ElementTree._ElementInterface-class'>#</a>]</dt>
<dd>
<p>Internal element class.</p>
<p>For more information about this class, see <a href='#elementtree.ElementTree._ElementInterface-class'><i>The _ElementInterface Class</i></a>.</p>
</dd>
<dt><a id='elementtree.ElementTree.Comment-function' name='elementtree.ElementTree.Comment-function'><b>Comment(text=None)</b></a> ⇒ Element [<a href='#elementtree.ElementTree.Comment-function'>#</a>]</dt>
<dd>
<p>Comment element factory. This factory function creates a special
element that will be serialized as an XML comment.
</p><p>
The comment string can be either an 8-bit ASCII string or a Unicode
string.
</p><dl>
<dt><i>text</i></dt>
<dd>
A string containing the comment string.</dd>
<dt>Returns:</dt>
<dd>
An element instance, representing a comment.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.dump-function' name='elementtree.ElementTree.dump-function'><b>dump(elem)</b></a> [<a href='#elementtree.ElementTree.dump-function'>#</a>]</dt>
<dd>
<p>Writes an element tree or element structure to sys.stdout. This
function should be used for debugging only.
</p><p>
The exact output format is implementation dependent. In this
version, it's written as an ordinary XML file.
</p><dl>
<dt><i>elem</i></dt>
<dd>
An element tree or an individual element.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.Element-function' name='elementtree.ElementTree.Element-function'><b>Element(tag, attrib={}, **extra)</b></a> ⇒ Element [<a href='#elementtree.ElementTree.Element-function'>#</a>]</dt>
<dd>
<p>Element factory. This function returns an object implementing the
standard Element interface. The exact class or type of that object
is implementation dependent, but it will always be compatible with
the <a class="link" href="#elementtree.ElementTree._ElementInterface-class"><b>_ElementInterface</b></a> class in this module.
</p><p>
The element name, attribute names, and attribute values can be
either 8-bit ASCII strings or Unicode strings.
</p><dl>
<dt><i>tag</i></dt>
<dd>
The element name.</dd>
<dt><i>attrib</i></dt>
<dd>
An optional dictionary, containing element attributes.</dd>
<dt><i>**extra</i></dt>
<dd>
Additional attributes, given as keyword arguments.</dd>
<dt>Returns:</dt>
<dd>
An element instance.</dd>
</dl><br />
</dd>
<dt><b>ElementTree(element=None, file=None)</b> (class) [<a href='#elementtree.ElementTree.ElementTree-class'>#</a>]</dt>
<dd>
<p>ElementTree wrapper class.</p>
<dl>
<dt><i>element</i></dt>
<dd>
Optional root element.</dd>
<dt><i>file=</i></dt>
<dd>
Optional file handle or name. If given, the
tree is initialized with the contents of this XML file.</dd>
</dl><br />
<p>For more information about this class, see <a href='#elementtree.ElementTree.ElementTree-class'><i>The ElementTree Class</i></a>.</p>
</dd>
<dt><a id='elementtree.ElementTree.fromstring-variable' name='elementtree.ElementTree.fromstring-variable'><b>fromstring</b></a> (variable) [<a href='#elementtree.ElementTree.fromstring-variable'>#</a>]</dt>
<dd>
<p>Parses an XML document from a string constant. Same as <a class="link" href="#elementtree.ElementTree.XML-function"><b>XML</b></a>.
</p><dl>
<dt><i>source</i></dt>
<dd>
A string containing XML data.</dd>
<dt>Returns:</dt>
<dd>
An Element instance.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.iselement-function' name='elementtree.ElementTree.iselement-function'><b>iselement(element)</b></a> ⇒ flag [<a href='#elementtree.ElementTree.iselement-function'>#</a>]</dt>
<dd>
<p>Checks if an object appears to be a valid element object.</p>
<dl>
<dt><i>An</i></dt>
<dd>
element instance.</dd>
<dt>Returns:</dt>
<dd>
A true value if this is an element object.</dd>
</dl><br />
</dd>
<dt><b>iterparse(source, events=None)</b> (class) [<a href='#elementtree.ElementTree.iterparse-class'>#</a>]</dt>
<dd>
<p>Parses an XML document into an element tree incrementally, and reports
what's going on to the user.</p>
<dl>
<dt><i>source</i></dt>
<dd>
A filename or file object containing XML data.</dd>
<dt><i>events</i></dt>
<dd>
A list of events to report back. If omitted, only "end"
events are reported.</dd>
<dt>Returns:</dt>
<dd>
A (event, elem) iterator.</dd>
</dl><br />
<p>For more information about this class, see <a href='#elementtree.ElementTree.iterparse-class'><i>The iterparse Class</i></a>.</p>
</dd>
<dt><a id='elementtree.ElementTree.parse-function' name='elementtree.ElementTree.parse-function'><b>parse(source, parser=None)</b></a> [<a href='#elementtree.ElementTree.parse-function'>#</a>]</dt>
<dd>
<p>Parses an XML document into an element tree.</p>
<dl>
<dt><i>source</i></dt>
<dd>
A filename or file object containing XML data.</dd>
<dt><i>parser</i></dt>
<dd>
An optional parser instance. If not given, the
standard <a class="link" href="#elementtree.ElementTree.XMLTreeBuilder-class"><b>XMLTreeBuilder</b></a> parser is used.
</dd>
<dt>Returns:</dt>
<dd>
An ElementTree instance</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.ProcessingInstruction-function' name='elementtree.ElementTree.ProcessingInstruction-function'><b>ProcessingInstruction(target, text=None)</b></a> ⇒ Element [<a href='#elementtree.ElementTree.ProcessingInstruction-function'>#</a>]</dt>
<dd>
<p>PI element factory. This factory function creates a special element
that will be serialized as an XML processing instruction.</p>
<dl>
<dt><i>target</i></dt>
<dd>
A string containing the PI target.</dd>
<dt><i>text</i></dt>
<dd>
A string containing the PI contents, if any.</dd>
<dt>Returns:</dt>
<dd>
An element instance, representing a PI.</dd>
</dl><br />
</dd>
<dt><b>QName(text_or_uri, tag=None)</b> (class) [<a href='#elementtree.ElementTree.QName-class'>#</a>]</dt>
<dd>
<p>QName wrapper.</p>
<dl>
<dt><i>text</i></dt>
<dd>
A string containing the QName value, in the form {uri}local,
or, if the tag argument is given, the URI part of a QName.</dd>
<dt><i>tag</i></dt>
<dd>
Optional tag. If given, the first argument is interpreted as
an URI, and this argument is interpreted as a local name.</dd>
<dt>Returns:</dt>
<dd>
An opaque object, representing the QName.</dd>
</dl><br />
<p>For more information about this class, see <a href='#elementtree.ElementTree.QName-class'><i>The QName Class</i></a>.</p>
</dd>
<dt><a id='elementtree.ElementTree.SubElement-function' name='elementtree.ElementTree.SubElement-function'><b>SubElement(parent, tag, attrib={}, **extra)</b></a> ⇒ Element [<a href='#elementtree.ElementTree.SubElement-function'>#</a>]</dt>
<dd>
<p>Subelement factory. This function creates an element instance, and
appends it to an existing element.
</p><p>
The element name, attribute names, and attribute values can be
either 8-bit ASCII strings or Unicode strings.
</p><dl>
<dt><i>parent</i></dt>
<dd>
The parent element.</dd>
<dt><i>tag</i></dt>
<dd>
The subelement name.</dd>
<dt><i>attrib</i></dt>
<dd>
An optional dictionary, containing element attributes.</dd>
<dt><i>**extra</i></dt>
<dd>
Additional attributes, given as keyword arguments.</dd>
<dt>Returns:</dt>
<dd>
An element instance.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.tostring-function' name='elementtree.ElementTree.tostring-function'><b>tostring(element, encoding=None)</b></a> ⇒ string [<a href='#elementtree.ElementTree.tostring-function'>#</a>]</dt>
<dd>
<p>Generates a string representation of an XML element, including all
subelements.</p>
<dl>
<dt><i>element</i></dt>
<dd>
An Element instance.</dd>
<dt>Returns:</dt>
<dd>
An encoded string containing the XML data.</dd>
</dl><br />
</dd>
<dt><b>TreeBuilder(element_factory=None)</b> (class) [<a href='#elementtree.ElementTree.TreeBuilder-class'>#</a>]</dt>
<dd>
<p>Generic element structure builder.</p>
<dl>
<dt><i>element_factory</i></dt>
<dd>
Optional element factory. This factory
is called to create new Element instances, as necessary.</dd>
</dl><br />
<p>For more information about this class, see <a href='#elementtree.ElementTree.TreeBuilder-class'><i>The TreeBuilder Class</i></a>.</p>
</dd>
<dt><a id='elementtree.ElementTree.XML-function' name='elementtree.ElementTree.XML-function'><b>XML(text)</b></a> ⇒ Element [<a href='#elementtree.ElementTree.XML-function'>#</a>]</dt>
<dd>
<p>Parses an XML document from a string constant. This function can
be used to embed "XML literals" in Python code.</p>
<dl>
<dt><i>source</i></dt>
<dd>
A string containing XML data.</dd>
<dt>Returns:</dt>
<dd>
An Element instance.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.XMLID-function' name='elementtree.ElementTree.XMLID-function'><b>XMLID(text)</b></a> ⇒ (Element, dictionary) [<a href='#elementtree.ElementTree.XMLID-function'>#</a>]</dt>
<dd>
<p>Parses an XML document from a string constant, and also returns
a dictionary which maps from element id:s to elements.</p>
<dl>
<dt><i>source</i></dt>
<dd>
A string containing XML data.</dd>
<dt>Returns:</dt>
<dd>
A tuple containing an Element instance and a dictionary.</dd>
</dl><br />
</dd>
<dt><b>XMLTreeBuilder(html=0, target=None)</b> (class) [<a href='#elementtree.ElementTree.XMLTreeBuilder-class'>#</a>]</dt>
<dd>
<p>Element structure builder for XML source data, based on the
expat parser.</p>
<dl>
<dt><i>target=</i></dt>
<dd>
Target object. If omitted, the builder uses an
instance of the standard <a class="link" href="#elementtree.ElementTree.TreeBuilder-class"><b>TreeBuilder</b></a> class.
</dd>
<dt><i>html=</i></dt>
<dd>
Predefine HTML entities. This flag is not supported
by the current implementation.</dd>
</dl><br />
<p>For more information about this class, see <a href='#elementtree.ElementTree.XMLTreeBuilder-class'><i>The XMLTreeBuilder Class</i></a>.</p>
</dd>
</dl>
<h2><a id='elementtree.ElementTree._ElementInterface-class' name='elementtree.ElementTree._ElementInterface-class'>The _ElementInterface Class</a></h2>
<dl>
<dt><b>_ElementInterface(tag, attrib)</b> (class) [<a href='#elementtree.ElementTree._ElementInterface-class'>#</a>]</dt>
<dd>
<p>Internal element class. This class defines the Element interface,
and provides a reference implementation of this interface.
</p><p>
You should not create instances of this class directly. Use the
appropriate factory functions instead, such as <a class="link" href="#elementtree.ElementTree.Element-function"><b>Element</b></a>
and <a class="link" href="#elementtree.ElementTree.SubElement-function"><b>SubElement</b></a>.
</p></dd>
<dt><a id='elementtree.ElementTree._ElementInterface.__delitem__-method' name='elementtree.ElementTree._ElementInterface.__delitem__-method'><b>__delitem__(index)</b></a> [<a href='#elementtree.ElementTree._ElementInterface.__delitem__-method'>#</a>]</dt>
<dd>
<p>Deletes the given subelement.</p>
<dl>
<dt><i>index</i></dt>
<dd>
What subelement to delete.</dd>
<dt>Raises <b>IndexError</b>:</dt><dd>
If the given element does not exist.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.__delslice__-method' name='elementtree.ElementTree._ElementInterface.__delslice__-method'><b>__delslice__(start, stop)</b></a> [<a href='#elementtree.ElementTree._ElementInterface.__delslice__-method'>#</a>]</dt>
<dd>
<p>Deletes a number of subelements.</p>
<dl>
<dt><i>start</i></dt>
<dd>
The first subelement to delete.</dd>
<dt><i>stop</i></dt>
<dd>
The first subelement to leave in there.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.__getitem__-method' name='elementtree.ElementTree._ElementInterface.__getitem__-method'><b>__getitem__(index)</b></a> [<a href='#elementtree.ElementTree._ElementInterface.__getitem__-method'>#</a>]</dt>
<dd>
<p>Returns the given subelement.</p>
<dl>
<dt><i>index</i></dt>
<dd>
What subelement to return.</dd>
<dt>Returns:</dt>
<dd>
The given subelement.</dd>
<dt>Raises <b>IndexError</b>:</dt><dd>
If the given element does not exist.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.__getslice__-method' name='elementtree.ElementTree._ElementInterface.__getslice__-method'><b>__getslice__(start, stop)</b></a> [<a href='#elementtree.ElementTree._ElementInterface.__getslice__-method'>#</a>]</dt>
<dd>
<p>Returns a list containing subelements in the given range.</p>
<dl>
<dt><i>start</i></dt>
<dd>
The first subelement to return.</dd>
<dt><i>stop</i></dt>
<dd>
The first subelement that shouldn't be returned.</dd>
<dt>Returns:</dt>
<dd>
A sequence object containing subelements.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.__len__-method' name='elementtree.ElementTree._ElementInterface.__len__-method'><b>__len__()</b></a> [<a href='#elementtree.ElementTree._ElementInterface.__len__-method'>#</a>]</dt>
<dd>
<p>Returns the number of subelements.</p>
<dl>
<dt>Returns:</dt>
<dd>
The number of subelements.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.__setitem__-method' name='elementtree.ElementTree._ElementInterface.__setitem__-method'><b>__setitem__(index, element)</b></a> [<a href='#elementtree.ElementTree._ElementInterface.__setitem__-method'>#</a>]</dt>
<dd>
<p>Replaces the given subelement.</p>
<dl>
<dt><i>index</i></dt>
<dd>
What subelement to replace.</dd>
<dt><i>element</i></dt>
<dd>
The new element value.</dd>
<dt>Raises <b>IndexError</b>:</dt><dd>
If the given element does not exist.</dd>
<dt>Raises <b>AssertionError</b>:</dt><dd>
If element is not a valid object.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.__setslice__-method' name='elementtree.ElementTree._ElementInterface.__setslice__-method'><b>__setslice__(start, stop, elements)</b></a> [<a href='#elementtree.ElementTree._ElementInterface.__setslice__-method'>#</a>]</dt>
<dd>
<p>Replaces a number of subelements with elements from a sequence.</p>
<dl>
<dt><i>start</i></dt>
<dd>
The first subelement to replace.</dd>
<dt><i>stop</i></dt>
<dd>
The first subelement that shouldn't be replaced.</dd>
<dt><i>elements</i></dt>
<dd>
A sequence object with zero or more elements.</dd>
<dt>Raises <b>AssertionError</b>:</dt><dd>
If a sequence member is not a valid object.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.append-method' name='elementtree.ElementTree._ElementInterface.append-method'><b>append(element)</b></a> [<a href='#elementtree.ElementTree._ElementInterface.append-method'>#</a>]</dt>
<dd>
<p>Adds a subelement to the end of this element.</p>
<dl>
<dt><i>element</i></dt>
<dd>
The element to add.</dd>
<dt>Raises <b>AssertionError</b>:</dt><dd>
If a sequence member is not a valid object.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.attrib-attribute' name='elementtree.ElementTree._ElementInterface.attrib-attribute'><b>attrib</b></a> [<a href='#elementtree.ElementTree._ElementInterface.attrib-attribute'>#</a>]</dt>
<dd>
<p>(Attribute) Element attribute dictionary. Where possible, use
<a class="link" href="#elementtree.ElementTree._ElementInterface.get-method"><b>get</b></a>,
<a class="link" href="#elementtree.ElementTree._ElementInterface.set-method"><b>set</b></a>,
<a class="link" href="#elementtree.ElementTree._ElementInterface.keys-method"><b>keys</b></a>, and
<a class="link" href="#elementtree.ElementTree._ElementInterface.items-method"><b>items</b></a> to access
element attributes.
</p></dd>
<dt><a id='elementtree.ElementTree._ElementInterface.clear-method' name='elementtree.ElementTree._ElementInterface.clear-method'><b>clear()</b></a> [<a href='#elementtree.ElementTree._ElementInterface.clear-method'>#</a>]</dt>
<dd>
<p>Resets an element. This function removes all subelements, clears
all attributes, and sets the text and tail attributes to None.</p>
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.find-method' name='elementtree.ElementTree._ElementInterface.find-method'><b>find(path)</b></a> ⇒ Element or None [<a href='#elementtree.ElementTree._ElementInterface.find-method'>#</a>]</dt>
<dd>
<p>Finds the first matching subelement, by tag name or path.</p>
<dl>
<dt><i>path</i></dt>
<dd>
What element to look for.</dd>
<dt>Returns:</dt>
<dd>
The first matching element, or None if no element was found.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.findall-method' name='elementtree.ElementTree._ElementInterface.findall-method'><b>findall(path)</b></a> ⇒ list of Element instances [<a href='#elementtree.ElementTree._ElementInterface.findall-method'>#</a>]</dt>
<dd>
<p>Finds all matching subelements, by tag name or path.</p>
<dl>
<dt><i>path</i></dt>
<dd>
What element to look for.</dd>
<dt>Returns:</dt>
<dd>
A list or iterator containing all matching elements,
in document order.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.findtext-method' name='elementtree.ElementTree._ElementInterface.findtext-method'><b>findtext(path, default=None)</b></a> ⇒ string [<a href='#elementtree.ElementTree._ElementInterface.findtext-method'>#</a>]</dt>
<dd>
<p>Finds text for the first matching subelement, by tag name or path.</p>
<dl>
<dt><i>path</i></dt>
<dd>
What element to look for.</dd>
<dt><i>default</i></dt>
<dd>
What to return if the element was not found.</dd>
<dt>Returns:</dt>
<dd>
The text content of the first matching element, or the
default value no element was found. Note that if the element
has is found, but has no text content, this method returns an
empty string.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.get-method' name='elementtree.ElementTree._ElementInterface.get-method'><b>get(key, default=None)</b></a> ⇒ string or None [<a href='#elementtree.ElementTree._ElementInterface.get-method'>#</a>]</dt>
<dd>
<p>Gets an element attribute.</p>
<dl>
<dt><i>key</i></dt>
<dd>
What attribute to look for.</dd>
<dt><i>default</i></dt>
<dd>
What to return if the attribute was not found.</dd>
<dt>Returns:</dt>
<dd>
The attribute value, or the default value, if the
attribute was not found.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.getchildren-method' name='elementtree.ElementTree._ElementInterface.getchildren-method'><b>getchildren()</b></a> ⇒ list of Element instances [<a href='#elementtree.ElementTree._ElementInterface.getchildren-method'>#</a>]</dt>
<dd>
<p>Returns all subelements. The elements are returned in document
order.</p>
<dl>
<dt>Returns:</dt>
<dd>
A list of subelements.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.getiterator-method' name='elementtree.ElementTree._ElementInterface.getiterator-method'><b>getiterator(tag=None)</b></a> ⇒ list or iterator [<a href='#elementtree.ElementTree._ElementInterface.getiterator-method'>#</a>]</dt>
<dd>
<p>Creates a tree iterator. The iterator loops over this element
and all subelements, in document order, and returns all elements
with a matching tag.
</p><p>
If the tree structure is modified during iteration, the result
is undefined.
</p><dl>
<dt><i>tag</i></dt>
<dd>
What tags to look for (default is to return all elements).</dd>
<dt>Returns:</dt>
<dd>
A list or iterator containing all the matching elements.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.insert-method' name='elementtree.ElementTree._ElementInterface.insert-method'><b>insert(index, element)</b></a> [<a href='#elementtree.ElementTree._ElementInterface.insert-method'>#</a>]</dt>
<dd>
<p>Inserts a subelement at the given position in this element.</p>
<dl>
<dt><i>index</i></dt>
<dd>
Where to insert the new subelement.</dd>
<dt>Raises <b>AssertionError</b>:</dt><dd>
If the element is not a valid object.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.items-method' name='elementtree.ElementTree._ElementInterface.items-method'><b>items()</b></a> ⇒ list of (string, string) tuples [<a href='#elementtree.ElementTree._ElementInterface.items-method'>#</a>]</dt>
<dd>
<p>Gets element attributes, as a sequence. The attributes are
returned in an arbitrary order.</p>
<dl>
<dt>Returns:</dt>
<dd>
A list of (name, value) tuples for all attributes.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.keys-method' name='elementtree.ElementTree._ElementInterface.keys-method'><b>keys()</b></a> ⇒ list of strings [<a href='#elementtree.ElementTree._ElementInterface.keys-method'>#</a>]</dt>
<dd>
<p>Gets a list of attribute names. The names are returned in an
arbitrary order (just like for an ordinary Python dictionary).</p>
<dl>
<dt>Returns:</dt>
<dd>
A list of element attribute names.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.makeelement-method' name='elementtree.ElementTree._ElementInterface.makeelement-method'><b>makeelement(tag, attrib)</b></a> [<a href='#elementtree.ElementTree._ElementInterface.makeelement-method'>#</a>]</dt>
<dd>
<p>Creates a new element object of the same type as this element.</p>
<dl>
<dt><i>tag</i></dt>
<dd>
Element tag.</dd>
<dt><i>attrib</i></dt>
<dd>
Element attributes, given as a dictionary.</dd>
<dt>Returns:</dt>
<dd>
A new element instance.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.remove-method' name='elementtree.ElementTree._ElementInterface.remove-method'><b>remove(element)</b></a> [<a href='#elementtree.ElementTree._ElementInterface.remove-method'>#</a>]</dt>
<dd>
<p>Removes a matching subelement. Unlike the <b>find</b> methods,
this method compares elements based on identity, not on tag
value or contents.
</p><dl>
<dt><i>element</i></dt>
<dd>
What element to remove.</dd>
<dt>Raises <b>ValueError</b>:</dt><dd>
If a matching element could not be found.</dd>
<dt>Raises <b>AssertionError</b>:</dt><dd>
If the element is not a valid object.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.set-method' name='elementtree.ElementTree._ElementInterface.set-method'><b>set(key, value)</b></a> [<a href='#elementtree.ElementTree._ElementInterface.set-method'>#</a>]</dt>
<dd>
<p>Sets an element attribute.</p>
<dl>
<dt><i>key</i></dt>
<dd>
What attribute to set.</dd>
<dt><i>value</i></dt>
<dd>
The attribute value.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.tag-attribute' name='elementtree.ElementTree._ElementInterface.tag-attribute'><b>tag</b></a> [<a href='#elementtree.ElementTree._ElementInterface.tag-attribute'>#</a>]</dt>
<dd>
<p>(Attribute) Element tag.</p>
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.tail-attribute' name='elementtree.ElementTree._ElementInterface.tail-attribute'><b>tail</b></a> [<a href='#elementtree.ElementTree._ElementInterface.tail-attribute'>#</a>]</dt>
<dd>
<p>(Attribute) Text after this element's end tag, but before the
next sibling element's start tag. This is either a string or
the value None, if there was no text.</p>
</dd>
<dt><a id='elementtree.ElementTree._ElementInterface.text-attribute' name='elementtree.ElementTree._ElementInterface.text-attribute'><b>text</b></a> [<a href='#elementtree.ElementTree._ElementInterface.text-attribute'>#</a>]</dt>
<dd>
<p>(Attribute) Text before first subelement. This is either a
string or the value None, if there was no text.</p>
</dd>
</dl>
<h2><a id='elementtree.ElementTree.ElementTree-class' name='elementtree.ElementTree.ElementTree-class'>The ElementTree Class</a></h2>
<dl>
<dt><b>ElementTree(element=None, file=None)</b> (class) [<a href='#elementtree.ElementTree.ElementTree-class'>#</a>]</dt>
<dd>
<p>ElementTree wrapper class. This class represents an entire element
hierarchy, and adds some extra support for serialization to and from
standard XML.</p>
<dl>
<dt><i>element</i></dt>
<dd>
Optional root element.</dd>
<dt><i>file=</i></dt>
<dd>
Optional file handle or name. If given, the
tree is initialized with the contents of this XML file.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.ElementTree._setroot-method' name='elementtree.ElementTree.ElementTree._setroot-method'><b>_setroot(element)</b></a> [<a href='#elementtree.ElementTree.ElementTree._setroot-method'>#</a>]</dt>
<dd>
<p>Replaces the root element for this tree. This discards the
current contents of the tree, and replaces it with the given
element. Use with care.</p>
<dl>
<dt><i>element</i></dt>
<dd>
An element instance.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.ElementTree.find-method' name='elementtree.ElementTree.ElementTree.find-method'><b>find(path)</b></a> ⇒ Element or None [<a href='#elementtree.ElementTree.ElementTree.find-method'>#</a>]</dt>
<dd>
<p>Finds the first toplevel element with given tag.
Same as getroot().find(path).</p>
<dl>
<dt><i>path</i></dt>
<dd>
What element to look for.</dd>
<dt>Returns:</dt>
<dd>
The first matching element, or None if no element was found.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.ElementTree.findall-method' name='elementtree.ElementTree.ElementTree.findall-method'><b>findall(path)</b></a> ⇒ list of Element instances [<a href='#elementtree.ElementTree.ElementTree.findall-method'>#</a>]</dt>
<dd>
<p>Finds all toplevel elements with the given tag.
Same as getroot().findall(path).</p>
<dl>
<dt><i>path</i></dt>
<dd>
What element to look for.</dd>
<dt>Returns:</dt>
<dd>
A list or iterator containing all matching elements,
in document order.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.ElementTree.findtext-method' name='elementtree.ElementTree.ElementTree.findtext-method'><b>findtext(path, default=None)</b></a> ⇒ string [<a href='#elementtree.ElementTree.ElementTree.findtext-method'>#</a>]</dt>
<dd>
<p>Finds the element text for the first toplevel element with given
tag. Same as getroot().findtext(path).</p>
<dl>
<dt><i>path</i></dt>
<dd>
What toplevel element to look for.</dd>
<dt><i>default</i></dt>
<dd>
What to return if the element was not found.</dd>
<dt>Returns:</dt>
<dd>
The text content of the first matching element, or the
default value no element was found. Note that if the element
has is found, but has no text content, this method returns an
empty string.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.ElementTree.getiterator-method' name='elementtree.ElementTree.ElementTree.getiterator-method'><b>getiterator(tag=None)</b></a> ⇒ iterator [<a href='#elementtree.ElementTree.ElementTree.getiterator-method'>#</a>]</dt>
<dd>
<p>Creates a tree iterator for the root element. The iterator loops
over all elements in this tree, in document order.</p>
<dl>
<dt><i>tag</i></dt>
<dd>
What tags to look for (default is to return all elements)</dd>
<dt>Returns:</dt>
<dd>
An iterator.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.ElementTree.getroot-method' name='elementtree.ElementTree.ElementTree.getroot-method'><b>getroot()</b></a> ⇒ Element [<a href='#elementtree.ElementTree.ElementTree.getroot-method'>#</a>]</dt>
<dd>
<p>Gets the root element for this tree.</p>
<dl>
<dt>Returns:</dt>
<dd>
An element instance.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.ElementTree.parse-method' name='elementtree.ElementTree.ElementTree.parse-method'><b>parse(source, parser=None)</b></a> ⇒ Element [<a href='#elementtree.ElementTree.ElementTree.parse-method'>#</a>]</dt>
<dd>
<p>Loads an external XML document into this element tree.</p>
<dl>
<dt><i>source</i></dt>
<dd>
A file name or file object.</dd>
<dt><i>parser</i></dt>
<dd>
An optional parser instance. If not given, the
standard <a class="link" href="#elementtree.ElementTree.XMLTreeBuilder-class"><b>XMLTreeBuilder</b></a> parser is used.
</dd>
<dt>Returns:</dt>
<dd>
The document root element.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.ElementTree.write-method' name='elementtree.ElementTree.ElementTree.write-method'><b>write(file, encoding="us-ascii")</b></a> [<a href='#elementtree.ElementTree.ElementTree.write-method'>#</a>]</dt>
<dd>
<p>Writes the element tree to a file, as XML.</p>
<dl>
<dt><i>file</i></dt>
<dd>
A file name, or a file object opened for writing.</dd>
<dt><i>encoding</i></dt>
<dd>
Optional output encoding (default is US-ASCII).</dd>
</dl><br />
</dd>
</dl>
<h2><a id='elementtree.ElementTree.iterparse-class' name='elementtree.ElementTree.iterparse-class'>The iterparse Class</a></h2>
<dl>
<dt><b>iterparse(source, events=None)</b> (class) [<a href='#elementtree.ElementTree.iterparse-class'>#</a>]</dt>
<dd>
<p>Parses an XML document into an element tree incrementally, and reports
what's going on to the user.</p>
<dl>
<dt><i>source</i></dt>
<dd>
A filename or file object containing XML data.</dd>
<dt><i>events</i></dt>
<dd>
A list of events to report back. If omitted, only "end"
events are reported.</dd>
<dt>Returns:</dt>
<dd>
A (event, elem) iterator.</dd>
</dl><br />
</dd>
</dl>
<h2><a id='elementtree.ElementTree.QName-class' name='elementtree.ElementTree.QName-class'>The QName Class</a></h2>
<dl>
<dt><b>QName(text_or_uri, tag=None)</b> (class) [<a href='#elementtree.ElementTree.QName-class'>#</a>]</dt>
<dd>
<p>QName wrapper. This can be used to wrap a QName attribute value, in
order to get proper namespace handling on output.</p>
<dl>
<dt><i>text</i></dt>
<dd>
A string containing the QName value, in the form {uri}local,
or, if the tag argument is given, the URI part of a QName.</dd>
<dt><i>tag</i></dt>
<dd>
Optional tag. If given, the first argument is interpreted as
an URI, and this argument is interpreted as a local name.</dd>
<dt>Returns:</dt>
<dd>
An opaque object, representing the QName.</dd>
</dl><br />
</dd>
</dl>
<h2><a id='elementtree.ElementTree.TreeBuilder-class' name='elementtree.ElementTree.TreeBuilder-class'>The TreeBuilder Class</a></h2>
<dl>
<dt><b>TreeBuilder(element_factory=None)</b> (class) [<a href='#elementtree.ElementTree.TreeBuilder-class'>#</a>]</dt>
<dd>
<p>Generic element structure builder. This builder converts a sequence
of <a class="link" href="#elementtree.ElementTree.TreeBuilder.start-method"><b>start</b></a>, <a class="link" href="#elementtree.ElementTree.TreeBuilder.data-method"><b>data</b></a>, and <a class="link" href="#elementtree.ElementTree.TreeBuilder.end-method"><b>end</b></a> method calls to a well-formed element structure.
</p><p>
You can use this class to build an element structure using a custom XML
parser, or a parser for some other XML-like format.
</p><dl>
<dt><i>element_factory</i></dt>
<dd>
Optional element factory. This factory
is called to create new Element instances, as necessary.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.TreeBuilder.close-method' name='elementtree.ElementTree.TreeBuilder.close-method'><b>close()</b></a> ⇒ Element [<a href='#elementtree.ElementTree.TreeBuilder.close-method'>#</a>]</dt>
<dd>
<p>Flushes the parser buffers, and returns the toplevel documen
element.</p>
<dl>
<dt>Returns:</dt>
<dd>
An Element instance.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.TreeBuilder.data-method' name='elementtree.ElementTree.TreeBuilder.data-method'><b>data(data)</b></a> [<a href='#elementtree.ElementTree.TreeBuilder.data-method'>#</a>]</dt>
<dd>
<p>Adds text to the current element.</p>
<dl>
<dt><i>data</i></dt>
<dd>
A string. This should be either an 8-bit string
containing ASCII text, or a Unicode string.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.TreeBuilder.end-method' name='elementtree.ElementTree.TreeBuilder.end-method'><b>end(tag)</b></a> ⇒ Element [<a href='#elementtree.ElementTree.TreeBuilder.end-method'>#</a>]</dt>
<dd>
<p>Closes the current element.</p>
<dl>
<dt><i>tag</i></dt>
<dd>
The element name.</dd>
<dt>Returns:</dt>
<dd>
The closed element.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.TreeBuilder.start-method' name='elementtree.ElementTree.TreeBuilder.start-method'><b>start(tag, attrs)</b></a> ⇒ Element [<a href='#elementtree.ElementTree.TreeBuilder.start-method'>#</a>]</dt>
<dd>
<p>Opens a new element.</p>
<dl>
<dt><i>tag</i></dt>
<dd>
The element name.</dd>
<dt><i>attrib</i></dt>
<dd>
A dictionary containing element attributes.</dd>
<dt>Returns:</dt>
<dd>
The opened element.</dd>
</dl><br />
</dd>
</dl>
<h2><a id='elementtree.ElementTree.XMLTreeBuilder-class' name='elementtree.ElementTree.XMLTreeBuilder-class'>The XMLTreeBuilder Class</a></h2>
<dl>
<dt><b>XMLTreeBuilder(html=0, target=None)</b> (class) [<a href='#elementtree.ElementTree.XMLTreeBuilder-class'>#</a>]</dt>
<dd>
<p>Element structure builder for XML source data, based on the
<b>expat</b> parser.
</p><dl>
<dt><i>target=</i></dt>
<dd>
Target object. If omitted, the builder uses an
instance of the standard <a class="link" href="#elementtree.ElementTree.TreeBuilder-class"><b>TreeBuilder</b></a> class.
</dd>
<dt><i>html=</i></dt>
<dd>
Predefine HTML entities. This flag is not supported
by the current implementation.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.XMLTreeBuilder.close-method' name='elementtree.ElementTree.XMLTreeBuilder.close-method'><b>close()</b></a> ⇒ Element [<a href='#elementtree.ElementTree.XMLTreeBuilder.close-method'>#</a>]</dt>
<dd>
<p>Finishes feeding data to the parser.</p>
<dl>
<dt>Returns:</dt>
<dd>
An element structure.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.XMLTreeBuilder.doctype-method' name='elementtree.ElementTree.XMLTreeBuilder.doctype-method'><b>doctype(name, pubid, system)</b></a> [<a href='#elementtree.ElementTree.XMLTreeBuilder.doctype-method'>#</a>]</dt>
<dd>
<p>Handles a doctype declaration.</p>
<dl>
<dt><i>name</i></dt>
<dd>
Doctype name.</dd>
<dt><i>pubid</i></dt>
<dd>
Public identifier.</dd>
<dt><i>system</i></dt>
<dd>
System identifier.</dd>
</dl><br />
</dd>
<dt><a id='elementtree.ElementTree.XMLTreeBuilder.feed-method' name='elementtree.ElementTree.XMLTreeBuilder.feed-method'><b>feed(data)</b></a> [<a href='#elementtree.ElementTree.XMLTreeBuilder.feed-method'>#</a>]</dt>
<dd>
<p>Feeds data to the parser.</p>
<dl>
<dt><i>data</i></dt>
<dd>
Encoded data.</dd>
</dl><br />
</dd>
</dl>
</body></html>
|