Android CDATA parsing with SAX, tag not removed

AbrarpCer

New Member
My xml contains some cdata\[code\]<desc><![CDATA[<p>This is my html text</p>]]></desc> \[/code\]My SAX parser is able to parse the xml cdata but the parsed text contains the tag 'CDATA'\[code\]<![CDATA[<p>This is my html text</p>]]>\[/code\]I would like to get only the html text inside the CDATA. I can use some string functions to remove that but I would like to know whether this is normal SAX behavior? This is my SAX Handler code:\[code\]public class SAXXMLHandler extends DefaultHandler {private List<Laptop> laptops;private Laptop laptop;private StringBuffer tempSB = new StringBuffer();public SAXXMLHandler() { laptops = new ArrayList<Laptop>();}public List<Laptop> getLaptops() { return laptops;}// Event Handlerspublic void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { tempSB.delete(0, tempSB.length()); if (qName.equalsIgnoreCase("laptop")) { laptop = new Laptop(); laptop.setModel(attributes.getValue("model")); }} public void characters(char[] ch, int start, int length) throws SAXException { tempSB.append(ch, start, length);} public void endElement(String uri, String localName, String qName) throws SAXException { if (qName.equalsIgnoreCase("laptop")) { laptops.add(laptop); } else if (qName.equalsIgnoreCase("id")) { laptop.setId(Integer.parseInt(tempSB.toString())); } else if (qName.equalsIgnoreCase("desc")) { laptop.setDescription(tempSB.toString()); } }}\[/code\]
 
Back
Top