Update of /cvsroot/python/python/dist/src/Doc/lib In directory usw-pr-cvs1:/tmp/cvs-serv13635 Modified Files: xmldomminidom.tex Log Message: Update an example to use the DOM implementation object. Explain that the parse() and parseString() functions use a separate parser, not actually implement a parser. (This is a common question.) Index: xmldomminidom.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/xmldomminidom.tex,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** xmldomminidom.tex 30 Jun 2002 15:04:59 -0000 1.6 --- xmldomminidom.tex 24 Oct 2002 19:36:04 -0000 1.7 *************** *** 28,32 **** \end{verbatim} ! The parse function can take either a filename or an open file object. \begin{funcdesc}{parse}{filename_or_file{, parser}} --- 28,33 ---- \end{verbatim} ! The \function{parse()} function can take either a filename or an open ! file object. \begin{funcdesc}{parse}{filename_or_file{, parser}} *************** *** 51,64 **** content of the document. ! You can also create a \class{Document} node merely by instantiating a ! document object. Then you could add child nodes to it to populate the DOM: \begin{verbatim} ! from xml.dom.minidom import Document ! newdoc = Document() ! newel = newdoc.createElement("some_tag") ! newdoc.appendChild(newel) \end{verbatim} --- 52,84 ---- content of the document. ! What the \function{parse()} and \function{parseString()} functions do ! is connect an XML parser with a ``DOM builder'' that can accept parse ! events from any SAX parser and convert them into a DOM tree. The name ! of the functions are perhaps misleading, but are easy to grasp when ! learning the interfaces. The parsing of the document will be ! completed before these functions return; it's simply that these ! functions do not provide a parser implementation themselves. ! ! You can also create a \class{Document} by calling a method on a ``DOM ! Implementation'' object. You can get this object either by calling ! the \function{getDOMImplementation()} function in the ! \refmodule{xml.dom} package or the \module{xml.dom.minidom} module. ! Using the implementation from the \module{xml.dom.minidom} module will ! always return a \class{Document} instance from the minidom ! implementation, while the version from \refmodule{xml.dom} may provide ! an alternate implementation (this is likely if you have the ! \ulink{PyXML package}{http://pyxml.sourceforge.net/} installed). Once ! you have a \class{Document}, you can add child nodes to it to populate the DOM: \begin{verbatim} ! from xml.dom.minidom import getDOMImplementation ! impl = getDOMImplementation() ! ! newdoc = impl.createDocument(None, "some_tag", None) ! top_element = newdoc.documentElement ! text = newdoc.createTextNode('Some textual content.') ! top_element.appendChild(text) \end{verbatim} *************** *** 101,105 **** ! \subsection{DOM objects \label{dom-objects}} The definition of the DOM API for Python is given as part of the --- 121,125 ---- ! \subsection{DOM Objects \label{dom-objects}} The definition of the DOM API for Python is given as part of the
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4