Re: How to get the value of an element

"Mukesh Kumar" <[email protected]>
Newsgroups gmane.text.xml.expat.general
Message-ID <7C83A8A6B56D3A478333B1DF47E18586A6C39F@MPBABGEX01.corp.mphasis.com>
 

Hi,

 Try this

 

 

import xml.parsers.expat

 

# 3 handler functions

def start_element(name, attrs):

    print 'Start element:', name, attrs

def end_element(name):

    print 'End element:', name

def char_data(data):

    print 'Character data:', repr(data)

 

p = xml.parsers.expat.ParserCreate()

 

p.StartElementHandler = start_element

p.EndElementHandler = end_element

p.CharacterDataHandler = char_data

 

p.Parse("""<?xml version="1.0"?>

<parent id="top"><child1 name="paul">Text goes here</child1>

<child2 name="fred">More text</child2>

</parent>""")

 

 

You can you a file to read the xml contents and read the xml document
and in  a while loop , and extract the contents.

 

 

Here is my small web-page:

http://www.geocities.com/muki_champs

 

Regards,

Mukesh Srivastav,

Sr.Software Engineer,

India,

Bangalore.

 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Bin Chen
Sent: Thursday, May 24, 2007 12:07 PM
To: [email protected]
Subject: [Expat-discuss] How to get the value of an element

 

Hi,

 

For a xml like:

 

<f1>

        <f2>

                abc

        </f2>

</f1>

 

 

The vaule of element f2 is abc, now I want to get this value, how can?

 

Thanks a lot.

 

Bin

 

_______________________________________________

Expat-discuss mailing list

[email protected]

http://mail.libexpat.org/mailman/listinfo/expat-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.