ActiveState Code

Recipe 275370: Extract text from XML document, II


Alternative way of extracting text from a WF XML source.

Python
1
2
3
4
5
6
7
8
9
from sgmllib import SGMLParser

class XMLJustText ( SGMLParser ) :
    def handle_data ( self, data ) :
        print data

XMLJustText  ( ) . feed ( 
"<items><item>text 1</item><item>text 2</item></items>" 
)

Discussion

Warning: I have not experimented with this approach sufficiently to know anything about it.

Sign in to comment