get textual content of a Xml element using 4DOM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • frankabel

    #1

    get textual content of a Xml element using 4DOM

    Hi all!
    I have the following xml file:
    "
    <items>
    <item>hi</item>
    <item>hello</item>
    </items>
    "
    and need to read all the content between <items> and </items> tags and
    saved in a string, in this case:
    "
    <item>hi</item>
    <item>hello</item>
    "
    Working with "xml.dom.minido m" I can use the
    "xml.dom.minido m.Node.toxml()" to obtain the string inside one node. But
    I wish to use 4DOM to load my DOM tree.

    Someone know a manner to make something like
    "xml.dom.minido m.Node.toxml()" using 4DOM?

    Why a lightweight implementation like "xml.dom.minido m" have this
    feature, while a 4DOM don't?

    Thanks




  • uche.ogbuji@gmail.com

    #2
    Re: get textual content of a Xml element using 4DOM

    I suggest using minidom or pxdom [1] rather than 4DOM. If you insist
    on using 4DOM, xml.dom.ext.Pri nt(node) or xml.dom.ext.Pre ttyPrint(node)
    does what you want.

    --Uche

    Comment

    • uche.ogbuji@gmail.com

      #3
      Re: get textual content of a Xml element using 4DOM

      I suggest using minidom or pxdom [1] rather than 4DOM. If you insist
      on using 4DOM, xml.dom.ext.Pri nt(node) or xml.dom.ext.Pre ttyPrint(node)
      does what you want.

      [1] http://www.doxdesk.com/software/py/pxdom.html

      --Uche

      Comment

      • Frank Abel Cancio Bello

        #4
        Re: get textual content of a Xml element using 4DOM

        Hi:

        PrettyPrint or Print return the value to the console, and i need keep this
        value in a string variable to work with it, how can i do this?

        thanks to Uche

        Frank Abel

        -----Original Message-----
        From: uche.ogbuji@gma il.com
        To: python-list@python.org
        Date: 4 Mar 2005 09:23:07 -0800
        Subject: Re: get textual content of a Xml element using 4DOM
        [color=blue]
        > I suggest using minidom or pxdom [1] rather than 4DOM. If you insist
        > on using 4DOM, xml.dom.ext.Pri nt(node) or xml.dom.ext.Pre ttyPrint(node)
        > does what you want.
        >
        > [1] http://www.doxdesk.com/software/py/pxdom.html
        >
        > --Uche
        >
        > --
        > http://mail.python.org/mailman/listinfo/python-list
        >
        >[/color]




        Comment

        • and-google@doxdesk.com

          #5
          Re: get textual content of a Xml element using 4DOM

          Frank Abel Cancio Bello <FRANKA...@esla .cujae.edu.cu> wrote:
          [color=blue]
          > PrettyPrint or Print return the value to the console, and i need
          > keep this value in a string variable to work with it, how can i
          > do this?[/color]

          The second parameter to either of these functions can be a stream
          object, so you can use a StringIO to get string output:

          from StringIO import StringIO
          from xml.dom.ext import Print

          buf= StringIO()
          Print(doc, buf)
          xml= buf.getvalue()

          --
          Andrew Clover

          mailto:and@doxd esk.com

          Comment

          Working...