[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: How to get the text kept between two html tags
Srinivasan_KS wrote: > I want to get the information kept between html tags or attributes. > How do I do this using EXPAT or using SAX? > EG:- > <TEXT1>INFO1<TEXT1> > <TEXT2>INFO2<TEXT2> > How to extract INFO1 and INFO2 and store it in some other file. Presumably, you mean XHTML or XML? Expat and other XML parsers won't work on non-well-formed HTML documents, which is most. In SAX, implement the DocumentHandler interface and register your implementation with a SAX-enabled parser. When the parser calls startElement(), you'll need to keep the element name (TEXT1 or TEXT2) as state. You can also retrieve attribute values at this time (they are passed to startElement). The parser will call characters() to pass you the text. Based on the state (TEXT1 or TEXT2), you can store it appropriately. Note that the parser can make multiple calls to characters() -- that is, it could call characters() five times (once for each character), once (with all the characters), or anything in between. -- Ron Bourret xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i... Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1 To (un)subscribe, mailto:majordomo@i... the following message; (un)subscribe xml-dev To subscribe to the digests, mailto:majordomo@i... the following message; subscribe xml-dev-digest List coordinator, Henry Rzepa (mailto:rzepa@i...)
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|