2 Replies Latest reply: Sep 9, 2008 6:45 AM by 807589 RSS

    How to remove/ignore the element using SAXParser

      hello all,

      I want to parse the text content in string from the existed xml file. but had problem with the parser. Does anyone have good idea, how to remove or ignore the <link> tag in tag <text>?

      IS: the output is only the rest of part text behind <link style="blue" src="www.test.com" />.
      Wanted: the whole text in <text> tags. like "Reach more customers by creating targeted micro-sites using test's multi-store retailing functionality."

      Given below is my code :
      <?xml version="1.0"?>
      <test xmlns="http://www.test.com/test">
      <title>test title</title>
      <text>Reach more customers by creating targeted micro-sites using test's<link style="blue" src="www.test.com" /> multi-store retailing functionality.</text>
      java code using SAXParser
        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
        public void endElement(String uri, String localName, String qName) throws SAXException {
          if (qName.equals("text")) {
            System.out.println("content: " + text);
        public void characters(char[] ch, int start, int length) throws SAXException {
          String str = new String(ch, start, length);
          if (str.length() > 0)
            text = text == null ? str : text + str;
      Edited by: lauehuang on Sep 9, 2008 4:37 AM