OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: How to get the text kept between two html tags

[ Lists Home | Date Index | Thread Index ]
  • From: Ronald Bourret <rbourret@ito.tu-darmstadt.de>
  • To: "'xml-dev@ic.ac.uk'" <xml-dev@ic.ac.uk>
  • Date: Thu, 12 Aug 1999 16:23:13 +0200

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@ic.ac.uk
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@ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS