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 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
|
<HTML>
<HEAD>
<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
<TITLE>4DOM Extensions</TITLE>
<STYLE TYPE='text/css'>
<!--
BODY {background: white}
A:link {font-weight: 600;
font-family: sans-serif;
color: blue;
text-decoration: none}
A:visited {font-weight: 600;
font-family: sans-serif;
color: #800080;
text-decoration: none}
A:active {font-weight: 600;
font-family: sans-serif;
color: #FF0000;
text-decoration: none}
A:hover {font-weight: 600;
font-family: sans-serif;
color: #FF0000;
text-decoration: none}
-->
</STYLE>
</HEAD>
<BODY>
<H1>4DOM Extensions</H1>
<BR>
<P>
These are utility classes and functions that provide capabilities not yet specified in the DOM spec. Some of these facilities, such as factories and readers are expected to be specified in later levels of the DOM, so we try to keep our proprietary interfaces simple for now so that you can more painlessly migrate when relevant standards emerge.
</P>
<P>
See the demo directory for examples exercising many of these extensions.
</P>
<H3>Reading</H3>
<P>
The Reader package allows you to parse source strings in XML and HTML into DOM trees. You select a reader module according to the nature of your input. The readers that come with 4DOM are as follows:
</P>
<DL>
<DT>
<I>PyExpat</I>
</DT>
<DD>
Read XML using pyexpat from PyXML. Does not support validation.
</DD>
<DT>
<I>HtmlLib</I>
</DT>
<DD>
Read HTML using Python's htmllib.
</DD>
<DT>
<I>Sax2</I>
</DT>
<DD>
Read XML using the PyXML SAX2 package. DTD validation is option.
</DD>
<DT>
<I>Sax (deprecated)</I>
</DT>
<DD>
Read XML using the PyXML SAX package. DTD validation is option.
</DD>
<DT>
<I>Sgmlop</I>
</DT>
<DD>
Read XML using Sgmlop from PyXML. Does not support validation.
</DD>
</DL>
<P>
The following two examples illustrate using PyExpat and HtmlLib readers. Replace with the appropriate module and use in your own code.
</P>
<PRE>
# Parse XML using pyexpat
from xml.dom.ext.reader import PyExpat
reader = PyExpat.Reader()
xml_doc = reader.fromStream(stream)
#Parse HTML using htmllib
from xml.dom.ext.reader import HtmlLib
reader = HtmlLib.Reader()
html_doc = reader.fromStream(stream)
</PRE>
<H2>Module PyExpat</H2>
<P>Parse XML using pyexpat</P>
<p>Module Summary</p>
<ul>
<li>
<a href='#CLASS'>Classes</a>
</li>
</ul>
<A name='COMMAND_LINE'></A>
<A name='TYPE_DEF'></A>
<A name='EXCEPTION'></A>
<A name='STRUCTURE'></A>
<A name='CLASS'></A>
<H3>Classes</H3>
<TABLE BORDER='1' CELLSPACING='0' WIDTH='600' CELLPADDING='3'>
<TR>
<TD BGCOLOR='#66FF66' COLSPAN='2'>
<BIG><B>Class Summary</B></BIG>
</TD>
</TR>
<TR>
<TD WIDTH='150' NOWRAP ALIGN='Leftt'>
<CODE><A HREF='#PyExpat.Reader'><B>Reader</B></A></CODE>
</TD>
<TD WIDTH='100%'>Reusable utility to read XML documents. </TD>
</TR>
</TABLE>
<P> </P>
<A NAME='PyExpat.Reader'></A>
<H4>Class Reader</H4>
<P>Reusable utility to read XML documents.</P>
<TABLE BORDER='1' CELLSPACING='0' WIDTH='600' CELLPADDING='3'>
<TR>
<TD BGCOLOR='#6666FF' COLSPAN='2'>
<BIG><B>Method Summary</B></BIG>
</TD>
</TR>
<TR>
<TD WIDTH='150' NOWRAP ALIGN='Leftt'>
<CODE><A HREF='#PyExpat.Reader.fromStream'><B>fromStream</B></A></CODE>
</TD>
<TD WIDTH='100%'>return a 4DOM node from the given stream </TD>
</TR>
<TR>
<TD WIDTH='150' NOWRAP ALIGN='Leftt'>
<CODE><A HREF='#PyExpat.Reader.fromString'><B>fromString</B></A></CODE>
</TD>
<TD WIDTH='100%'>return a 4DOM node from the given string </TD>
</TR>
<TR>
<TD WIDTH='150' NOWRAP ALIGN='Leftt'>
<CODE><A HREF='#PyExpat.Reader.fromUri'><B>fromUri</B></A></CODE>
</TD>
<TD WIDTH='100%'>return a 4DOM node from the given uri </TD>
</TR>
</TABLE>
<P> </P>
<TABLE BORDER='1' WIDTH='600' CELLSPACING='0' BGCOLOR='#6666FF' CELLPADDING='3'>
<TR>
<TD>
<BIG><B>Method Details</B></BIG>
</TD>
</TR>
</TABLE>
<DIV bgcolor='#66FF66'>
<A NAME='PyExpat.Reader.fromStream'></A>
<H4>fromStream</H4>
<PRE>fromStream(stream, ownerDoc)
</PRE>
<BLOCKQUOTE>
<P>return a 4DOM node from the given stream</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>stream</CODE>
of type
<I>Python file object</I>
<BR>
</DT>
<DD>
<P>The stream to be read for XML text</P>
</DD>
<DT>
<CODE>ownerDoc</CODE>
of type
<I>xml.dom.Document.Document</I>
<BR>
</DT>
<DD>
<P>A document to be used as owner of all the created nodes. If None, a new document instance is created for the nodes. Default is None.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I></I>
</DT>
<DD>
<P>a new document instance, or if the ownerDoc argument was not None, a document fragment. In either case, the returned node roots the created XML tree.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='PyExpat.Reader.fromString'></A>
<H4>fromString</H4>
<PRE>fromString(xmlString, ownerDoc)
</PRE>
<BLOCKQUOTE>
<P>return a 4DOM node from the given string</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>xmlString</CODE>
of type
<I>string or unicode object</I>
<BR>
</DT>
<DD>
<P>The string to be parsed for XML text</P>
</DD>
<DT>
<CODE>ownerDoc</CODE>
of type
<I>xml.dom.Document.Document</I>
<BR>
</DT>
<DD>
<P>A document to be used as owner of all the created nodes. If None, a new document instance is created for the nodes. Default is None.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I></I>
</DT>
<DD>
<P>a new document instance, or if the ownerDoc argument was not None, a document fragment. In either case, the returned node roots the created XML tree.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='PyExpat.Reader.fromUri'></A>
<H4>fromUri</H4>
<PRE>fromUri(uri, ownerDoc)
</PRE>
<BLOCKQUOTE>
<P>return a 4DOM node from the given uri</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>uri</CODE>
of type
<I>Python file object</I>
<BR>
</DT>
<DD>
<P>The uri from which XML text is to be retrieved</P>
</DD>
<DT>
<CODE>ownerDoc</CODE>
of type
<I>xml.dom.Document.Document</I>
<BR>
</DT>
<DD>
<P>A document to be used as owner of all the created nodes. If None, a new document instance is created for the nodes. Default is None.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I></I>
</DT>
<DD>
<P>a new document instance, or if the ownerDoc argument was not None, a document fragment. In either case, the returned node roots the created XML tree.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<A name='FUNCTION'></A>
<H2>Module HtmlLib</H2>
<P>Parse HTML using htmllib</P>
<p>Module Summary</p>
<ul>
<li>
<a href='#CLASS'>Classes</a>
</li>
</ul>
<A name='COMMAND_LINE'></A>
<A name='TYPE_DEF'></A>
<A name='EXCEPTION'></A>
<A name='STRUCTURE'></A>
<A name='CLASS'></A>
<H3>Classes</H3>
<TABLE BORDER='1' CELLSPACING='0' WIDTH='600' CELLPADDING='3'>
<TR>
<TD BGCOLOR='#66FF66' COLSPAN='2'>
<BIG><B>Class Summary</B></BIG>
</TD>
</TR>
<TR>
<TD WIDTH='150' NOWRAP ALIGN='Leftt'>
<CODE><A HREF='#HtmlLib.Reader'><B>Reader</B></A></CODE>
</TD>
<TD WIDTH='100%'>Reusable utility to read HTML documents. </TD>
</TR>
</TABLE>
<P> </P>
<A NAME='HtmlLib.Reader'></A>
<H4>Class Reader</H4>
<P>Reusable utility to read HTML documents.</P>
<TABLE BORDER='1' CELLSPACING='0' WIDTH='600' CELLPADDING='3'>
<TR>
<TD BGCOLOR='#6666FF' COLSPAN='2'>
<BIG><B>Method Summary</B></BIG>
</TD>
</TR>
<TR>
<TD WIDTH='150' NOWRAP ALIGN='Leftt'>
<CODE><A HREF='#HtmlLib.Reader.fromStream'><B>fromStream</B></A></CODE>
</TD>
<TD WIDTH='100%'>return a 4DOM node from the given stream </TD>
</TR>
<TR>
<TD WIDTH='150' NOWRAP ALIGN='Leftt'>
<CODE><A HREF='#HtmlLib.Reader.fromString'><B>fromString</B></A></CODE>
</TD>
<TD WIDTH='100%'>return a 4DOM node from the given string </TD>
</TR>
<TR>
<TD WIDTH='150' NOWRAP ALIGN='Leftt'>
<CODE><A HREF='#HtmlLib.Reader.fromUri'><B>fromUri</B></A></CODE>
</TD>
<TD WIDTH='100%'>return a 4DOM node from the given uri </TD>
</TR>
</TABLE>
<P> </P>
<TABLE BORDER='1' WIDTH='600' CELLSPACING='0' BGCOLOR='#6666FF' CELLPADDING='3'>
<TR>
<TD>
<BIG><B>Method Details</B></BIG>
</TD>
</TR>
</TABLE>
<DIV bgcolor='#66FF66'>
<A NAME='HtmlLib.Reader.fromStream'></A>
<H4>fromStream</H4>
<PRE>fromStream(stream, ownerDoc, charset)
</PRE>
<BLOCKQUOTE>
<P>return a 4DOM node from the given stream</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>stream</CODE>
of type
<I>Python file object</I>
<BR>
</DT>
<DD>
<P>The stream to be read for HTML text</P>
</DD>
<DT>
<CODE>ownerDoc</CODE>
of type
<I>xml.dom.Document.Document</I>
<BR>
</DT>
<DD>
<P>A document to be used as owner of all the created nodes. If None, a new document instance is created for the nodes. Default is None.</P>
</DD>
<DT>
<CODE>charset</CODE>
of type
<I>string</I>
<BR>
</DT>
<DD>
<P>The character set of the HTML text. If None or empty string, the default is ISO-8859-1. Default is empty string.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I></I>
</DT>
<DD>
<P>a new document instance, or if the ownerDoc argument was not None, a document fragment. In either case, the returned node roots the created HTML tree.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='HtmlLib.Reader.fromString'></A>
<H4>fromString</H4>
<PRE>fromString(htmlString, ownerDoc, charset)
</PRE>
<BLOCKQUOTE>
<P>return a 4DOM node from the given string</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>htmlString</CODE>
of type
<I>string or unicode object</I>
<BR>
</DT>
<DD>
<P>The string to be parsed for HTML text</P>
</DD>
<DT>
<CODE>ownerDoc</CODE>
of type
<I>xml.dom.Document.Document</I>
<BR>
</DT>
<DD>
<P>A document to be used as owner of all the created nodes. If None, a new document instance is created for the nodes. Default is None.</P>
</DD>
<DT>
<CODE>charset</CODE>
of type
<I>string</I>
<BR>
</DT>
<DD>
<P>The character set of the HTML text. If None or empty string, the default is ISO-8859-1. Default is empty string.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I></I>
</DT>
<DD>
<P>a new document instance, or if the ownerDoc argument was not None, a document fragment. In either case, the returned node roots the created HTML tree.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='HtmlLib.Reader.fromUri'></A>
<H4>fromUri</H4>
<PRE>fromUri(uri, ownerDoc, charset)
</PRE>
<BLOCKQUOTE>
<P>return a 4DOM node from the given uri</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>uri</CODE>
of type
<I>Python file object</I>
<BR>
</DT>
<DD>
<P>The uri from which HTML text is to be retrieved</P>
</DD>
<DT>
<CODE>ownerDoc</CODE>
of type
<I>xml.dom.Document.Document</I>
<BR>
</DT>
<DD>
<P>A document to be used as owner of all the created nodes. If None, a new document instance is created for the nodes. Default is None.</P>
</DD>
<DT>
<CODE>charset</CODE>
of type
<I>string</I>
<BR>
</DT>
<DD>
<P>The character set of the HTML text. If None or empty string, the default is ISO-8859-1. Default is empty string.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I></I>
</DT>
<DD>
<P>a new document instance, or if the ownerDoc argument was not None, a document fragment. In either case, the returned node roots the created HTML tree.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<A name='FUNCTION'></A>
<H3>Printing/Writing</H3>
<P>The Printer module allows you to write a text representation of DOM nodes
to an output stream, including stdout. Note that limitations in the
SAX interface used to parse in XML files, and in the DOM spec itself make
it impossible at this point to handle an unchanged "round trip".
That is, if you use the builder to build a DOM node from text and then
use the Printer to turn it back to text, there may be differences;
some may be significant.
</P>
<P>The easiest way to use the Printer module is through the front-end functions in the xml.dom.ext package.</P>
<DIV bgcolor='#66FF66'>
<A NAME='xml.dom.ext.Print'></A>
<H4>xml.dom.ext.Print</H4>
<PRE>xml.dom.ext.Print(root, stream, encoding)
</PRE>
<BLOCKQUOTE>
<P>Render the DOM tree to text with no special formatting.</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>root</CODE>
of type
<I>xml.dom.Node</I>
<BR>
</DT>
<DD>
<P>The node to be printed, with all its children recursively.</P>
</DD>
<DT>
<CODE>stream</CODE>
of type
<I>output stream</I>
<BR>
</DT>
<DD>
<P>The output stream. Note: can be a StringIO object if you want to generate a string instead. Default is sys.stdout.</P>
</DD>
<DT>
<CODE>encoding</CODE>
of type
<I>string</I>
<BR>
</DT>
<DD>
<P>The character encoding to use for output. Default is 'UTF-8'.</P>
</DD>
</DL>
<B>Return Value</B>
<BLOCKQUOTE>
None
</BLOCKQUOTE>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='xml.dom.ext.PrettyPrint'></A>
<H4>xml.dom.ext.PrettyPrint</H4>
<PRE>xml.dom.ext.PrettyPrint(root, stream, encoding, indent, width, preserveElements)
</PRE>
<BLOCKQUOTE>
<P>Render the DOM tree to text, with added indentation and new-lines for enhanced readability.</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>root</CODE>
of type
<I>xml.dom.Node</I>
<BR>
</DT>
<DD>
<P>The node to be pretty-printed, with all its children recursively.</P>
</DD>
<DT>
<CODE>stream</CODE>
of type
<I>output stream</I>
<BR>
</DT>
<DD>
<P>The output stream. Note: can be a StringIO object if you want to generate a string instead. Default is sys.stdout.</P>
</DD>
<DT>
<CODE>encoding</CODE>
of type
<I>string</I>
<BR>
</DT>
<DD>
<P>The character encoding to use for output. Default is 'UTF-8'.</P>
</DD>
<DT>
<CODE>indent</CODE>
of type
<I>string</I>
<BR>
</DT>
<DD>
<P>The amount by which nested constructs are indented when printed on a fresh line. Default is '\t'.</P>
</DD>
<DT>
<CODE>width</CODE>
of type
<I>positive integer</I>
<BR>
</DT>
<DD>
<P>The width of the output console. Used to make
line-break decisions. Default is 80.</P>
</DD>
<DT>
<CODE>preserveElements</CODE>
of type
<I>list of strings, each of which is an SGML generic identifier.</I>
<BR>
</DT>
<DD>
<P>Specifes elements in which white-space shouldn't be added. Note that white-space is never added to in-line elements in an HTMLDocument. Default is None.</P>
</DD>
</DL>
<B>Return Value</B>
<BLOCKQUOTE>
None
</BLOCKQUOTE>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='xml.dom.ext.XHtmlPrint'></A>
<H4>xml.dom.ext.XHtmlPrint</H4>
<PRE>xml.dom.ext.XHtmlPrint(root, stream, encoding)
</PRE>
<BLOCKQUOTE>
<P>Render an HTML DOM tree as XHTML with no special indentation or formatting.</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>root</CODE>
of type
<I>xml.dom.Node</I>
<BR>
</DT>
<DD>
<P>The HTML node to be printed, with all its children recursively.</P>
</DD>
<DT>
<CODE>stream</CODE>
of type
<I>output stream</I>
<BR>
</DT>
<DD>
<P>The output stream. Note: can be a StringIO object if you want to generate a string instead. Default is sys.stdout.</P>
</DD>
<DT>
<CODE>encoding</CODE>
of type
<I>string</I>
<BR>
</DT>
<DD>
<P>The character encoding to use for output. Default is 'UTF-8'.</P>
</DD>
</DL>
<B>Return Value</B>
<BLOCKQUOTE>
None
</BLOCKQUOTE>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='xml.dom.ext.XHtmlPrettyPrint'></A>
<H4>xml.dom.ext.XHtmlPrettyPrint</H4>
<PRE>xml.dom.ext.XHtmlPrettyPrint(root, stream, encoding, indent, width, preserveElements)
</PRE>
<BLOCKQUOTE>
<P>Render an HTML DOM tree to text, with added indentation and new-lines for enhanced readability.</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>root</CODE>
of type
<I>xml.dom.Node</I>
<BR>
</DT>
<DD>
<P>The node to be pretty-printed, with all its children recursively.</P>
</DD>
<DT>
<CODE>stream</CODE>
of type
<I>output stream</I>
<BR>
</DT>
<DD>
<P>The output stream. Note: can be a StringIO object if you want to generate a string instead. Default is sys.stdout.</P>
</DD>
<DT>
<CODE>encoding</CODE>
of type
<I>string</I>
<BR>
</DT>
<DD>
<P>The character encoding to use for output. Default is 'UTF-8'.</P>
</DD>
<DT>
<CODE>indent</CODE>
of type
<I>string</I>
<BR>
</DT>
<DD>
<P>The amount by which nested constructs are indented when printed on a fresh line. Default is '\t'.</P>
</DD>
<DT>
<CODE>width</CODE>
of type
<I>positive integer</I>
<BR>
</DT>
<DD>
<P>The width of the output console. Used to make
line-break decisions. Default is 80.</P>
</DD>
<DT>
<CODE>preserveElements</CODE>
of type
<I>list of strings, each of which is an SGML generic identifier.</I>
<BR>
</DT>
<DD>
<P>Specifes elements in which white-space shouldn't be added. Note that white-space is never added to in-line elements in an HTMLDocument. Default is None.</P>
</DD>
</DL>
<B>Return Value</B>
<BLOCKQUOTE>
None
</BLOCKQUOTE>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<H3>Miscellaneous</H3>
<DIV bgcolor='#66FF66'>
<A NAME='xml.dom.ext.NodeTypeToInterface'></A>
<H4>xml.dom.ext.NodeTypeToInterface</H4>
<PRE>xml.dom.ext.NodeTypeToInterface(nodeType)
</PRE>
<BLOCKQUOTE>
<P>Look up a node type (as returned from getNodeType()) and returns a corresponding interface name.</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>nodeType</CODE>
of type
<I>One of the integers defined as node types in xml.dom.Node</I>
<BR>
</DT>
<DD>
<P>The node type to look up.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I>string</I>
</DT>
<DD>
<P>Name of corresponding DOM interface from spec.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='xml.dom.ext.StripHtml'></A>
<H4>xml.dom.ext.StripHtml</H4>
<PRE>xml.dom.ext.StripHtml(startNode, preserveElements)
</PRE>
<BLOCKQUOTE>
<P>Strips extraneous white-space from an HTML DOM tree.</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>startNode</CODE>
of type
<I>xml.dom.Node</I>
<BR>
</DT>
<DD>
<P>The node to be stripped, with all its children recursively.</P>
</DD>
<DT>
<CODE>preserveElements</CODE>
of type
<I>list of strings, each of which is an SGML generic identifier, or None to indicate an empty list.</I>
<BR>
</DT>
<DD>
<P>Specifes elements from which white-space shouldn't be stripped. Note that white-space is never stripped from in-line elements in an HTMLDocument. Default is None.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I>xml.dom.Node</I>
</DT>
<DD>
<P>The startNode with descendant ignorable white-space stripped.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='xml.dom.ext.StripXml'></A>
<H4>xml.dom.ext.StripXml</H4>
<PRE>xml.dom.ext.StripXml(startNode, preserveElements)
</PRE>
<BLOCKQUOTE>
<P>Strips extraneous white-space from an XML DOM tree. Takes xml:space attributes into account.</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>startNode</CODE>
of type
<I>xml.dom.Node</I>
<BR>
</DT>
<DD>
<P>The node to be stripped, with all its children recursively.</P>
</DD>
<DT>
<CODE>preserveElements</CODE>
of type
<I>list of strings, each of which is an SGML generic identifier, or None to indicate an empty list.</I>
<BR>
</DT>
<DD>
<P>Specifes elements from which white-space shouldn't be stripped. Default is None.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I>xml.dom.Node</I>
</DT>
<DD>
<P>The startNode with descendant ignorable white-space stripped.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='xml.dom.ext.GetElementById'></A>
<H4>xml.dom.ext.GetElementById</H4>
<PRE>xml.dom.ext.GetElementById(startNode, targetId)
</PRE>
<BLOCKQUOTE>
<P>Returns the element node whose "ID" attribute is as given.</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>startNode</CODE>
of type
<I>xml.dom.Node</I>
<BR>
</DT>
<DD>
<P>The node whose descendants are to be searched.</P>
</DD>
<DT>
<CODE>targetId</CODE>
of type
<I>string conforming to XML ID type</I>
<BR>
</DT>
<DD>
<P>The XML ID to find.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I>xml.dom.Element</I>
</DT>
<DD>
<P>The elemtn with the given ID, or None to indicate no match.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='xml.dom.ext.GetAllNs'></A>
<H4>xml.dom.ext.GetAllNs</H4>
<PRE>xml.dom.ext.GetAllNs(node)
</PRE>
<BLOCKQUOTE>
<P>Returns all the namespaces in effect on the given node, including the default namespace and the xml namespace.</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>node</CODE>
of type
<I>xml.dom.Node</I>
<BR>
</DT>
<DD>
<P>The node for which all in-scope namespaces are returned.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I>doctionary</I>
</DT>
<DD>
<P>Dictionary mapping all in-scope namespaces to URIs, with '' as prefix for the default namespace.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='xml.dom.ext.XmlSpaceState'></A>
<H4>xml.dom.ext.XmlSpaceState</H4>
<PRE>xml.dom.ext.XmlSpaceState(node)
</PRE>
<BLOCKQUOTE>
<P>Determines whether the xml:space state at a given node is "preserve" or "default" (See the XML 1.0 spec).</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>node</CODE>
of type
<I>xml.dom.Node</I>
<BR>
</DT>
<DD>
<P>The node whose space state is to be found.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I>string</I>
</DT>
<DD>
<P>"preserve" or "default".</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
<DIV bgcolor='#66FF66'>
<A NAME='xml.dom.ext.SplitQName'></A>
<H4>xml.dom.ext.SplitQName</H4>
<PRE>xml.dom.ext.SplitQName(qname)
</PRE>
<BLOCKQUOTE>
<P>Splits a valid QName from the XML Namespaces 1.0 spec into prefix and suffix (the local name in the case of element and attribute names, and the declared prefix in the case of namespace declarations.</P>
<B>Parameters</B>
<DL>
<DT>
<CODE>qname</CODE>
of type
<I>string matching QName production in XML Namespaces 1.0 spec</I>
<BR>
</DT>
<DD>
<P>The name to be split.</P>
</DD>
</DL>
<B>Return Value</B>
<DL>
<DT>
<I>tuple with 2 items.</I>
</DT>
<DD>
<P>a tuple of the form (prefix, suffix). If there is exactly one colon in the qname, prefix is the part before and suffix the part after the colon. Otherwise prefix is '' and suffix is the entire input string.</P>
</DD>
</DL>
</BLOCKQUOTE>
</DIV>
<BR>
<HR>
</BODY>
</HTML>
|