Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to remove/ignore the element using SAXParser

807589Sep 9 2008 — edited Sep 9 2008
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>
</test>
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 7 2008
Added on Sep 9 2008
2 comments
829 views