Re: How to get the value of an element

Bin Chen <[email protected]>
Newsgroups gmane.text.xml.expat.general
Message-ID <1179991328.19416.3.camel@binch-desktop>
Thanks, but that's not I want, I translate below code to C and run, then
find many useless char is also captured. I don't need any other useless
char other than the value of f2, is there any better way to do this?

The CharacterDataHandler seems a handler for every char that not
processed by "element handler", is it right? So something like '\t' and
'\n' are also be handled, and it's totally context free.

I want the content of f2, it is context sensitive, there are no API for
this?
在 2007-05-24四的 12:28 +0530,Mukesh Kumar写道:
>  
> 
> 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
> 
> 

_______________________________________________
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.