Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6656205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:36:52+00:00 2026-05-26T01:36:52+00:00

I’m having a problem with SAX XML parser. It Does parse everything, except quotation

  • 0

I’m having a problem with SAX XML parser.
It Does parse everything, except quotation marks (“).
For example, if the text is hell"3o in a node, the result is hell.

Here are my codes:
XML Handler:

public class MyXMLHandler extends DefaultHandler {

Boolean currentElement = false;
String currentValue = null;
public static SitesList sitesList = null;

public static SitesList getSitesList() {
return sitesList;
}

public static void setSitesList(SitesList sitesList) {
MyXMLHandler.sitesList = sitesList;
}

/** Called when tag starts ( ex:- <name>AndroidPeople</name>
* -- <name> )*/
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {

currentElement = true;

if (localName.equals("channel"))
{
/** Start */
sitesList = new SitesList();
} else if (localName.equals("item")) {
    String attr=attributes.getValue("item");
    sitesList.setItem(attr);
} else if (localName.equals("title")) {
/** Get attribute value */
String attr = attributes.getValue("title");
sitesList.setTitle(attr);
}
else if (localName.equals("link")) {
/** Get attribute value */
String attr = attributes.getValue("link");
sitesList.setLink(attr);
}
else if (localName.equals("description")) {
/** Get attribute value */
String attr = attributes.getValue("description");
sitesList.setDescription(attr);
}
else if (localName.equalsIgnoreCase("pubDate")) {
/** Get attribute value */
String attr = attributes.getValue("pubDate");
sitesList.setPubDate(attr);
}

}

/** Called when tag closing ( ex:- <name>AndroidPeople</name>
* -- </name> )*/
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {

currentElement = false;

/** set value */
if (localName.equalsIgnoreCase("item"))
sitesList.setItem(currentValue);
else if (localName.equalsIgnoreCase("title"))
sitesList.setTitle(currentValue);
else if (localName.equalsIgnoreCase("link"))
sitesList.setLink(currentValue);
else if (localName.equalsIgnoreCase("description"))
sitesList.setDescription(currentValue);
else if (localName.equalsIgnoreCase("pubDate"))
sitesList.setPubDate(currentValue);

}

/** Called to get tag characters ( ex:- <name>AndroidPeople</name>
* -- to get AndroidPeople Character ) */
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {

if (currentElement) {
currentValue = new String(ch, start, length);
currentElement = false;
}

}

}

Getter and Setter:

import java.util.ArrayList;

/** Contains getter and setter method for variables */
public class SitesList {

/** Variables */
private ArrayList<String> title = new ArrayList<String>();
private ArrayList<String> link = new ArrayList<String>();
private ArrayList<String> description = new ArrayList<String>();
private ArrayList<String> pubDate = new ArrayList<String>();
private ArrayList<String> item=new ArrayList<String>();



/** In Setter method default it will return arraylist
* change that to add */

public ArrayList<String> getTitle() {
return title;
}

public void setTitle(String title) {
this.title.add(title);
}

public ArrayList<String> getLink() {
return link;
}

public void setLink(String link) {
this.link.add(link);
}

public ArrayList<String> getDescription() {
return description;
}

public void setDescription(String description) {
this.description.add(description);
}
public ArrayList<String> getPubDate() {
    return this.pubDate;
}
public void setPubDate(String PubDate) {
    this.pubDate.add(PubDate);
}
public ArrayList<String> getItem() {
    return this.item;
}
public void setItem(String item) {
    this.item.add(item);
}



}

And RSS Thread class:

public class RssThread {

private String title,html,pubDate;
public RssThread(String title,String html,String pubDate)
{
    this.title=title;
    this.html=html;
    this.pubDate=CovertToDate(pubDate);
}
private String CovertToDate(String pubDate) {
    // TODO Auto-generated method stub
    //Wed, 28 Sep 2011 11:40:51//
    String newDate="";
    if (pubDate.substring(0,pubDate.indexOf(",")).equals("Sun"))
        newDate+="יום ראשון";
    else if (pubDate.subSequence(0, pubDate.indexOf(",")).equals("Mon"))
        newDate+="יום שני";
    else if (pubDate.subSequence(0, pubDate.indexOf(",")).equals("Tue"))
        newDate+="יום שלישי";
    else if (pubDate.subSequence(0, pubDate.indexOf(",")).equals("Wed"))
        newDate+="יום רביעי";
    else if (pubDate.subSequence(0, pubDate.indexOf(",")).equals("Thu"))
        newDate+="יום חמישי";
    else if (pubDate.subSequence(0, pubDate.indexOf(",")).equals("Fri"))
        newDate+="יום שישי";
    else if (pubDate.subSequence(0, pubDate.indexOf(",")).equals("Sat"))
        newDate+="יום שבת";
    newDate+=", ";
    String[] splited = pubDate.split(" ");
    newDate += splited[1]+".";
    if (splited[2].equals("Jan"))
        newDate+="1.";
    else if (splited[2].equals("Feb"))
        newDate+="2.";
    else if (splited[2].equals("Mar"))
        newDate+="3.";
    else if (splited[2].equals("Apr"))
        newDate+="4.";
    else if (splited[2].equals("May"))
        newDate+="5.";
    else if (splited[2].equals("Jun"))
        newDate+="6.";
    else if (splited[2].equals("Jul"))
        newDate+="7.";
    else if (splited[2].equals("Aug"))
        newDate+="8.";
    else if (splited[2].equals("Sep"))
        newDate+="9.";
    else if (splited[2].equals("Oct"))
        newDate+="10.";
    else if (splited[2].equals("Nov"))
        newDate+="11.";
    else if (splited[2].equals("Dec"))
        newDate+="12.";
    newDate+=splited[3];
    newDate+=", בשעה "+splited[4].substring(0,splited[4].lastIndexOf(":"));
    return newDate;

}
public String getTitle() {
    return this.title;
}
public String getHTML() {
    return html;
}
public String getPubDate() {
    return this.pubDate;
}
}

I have forgotten to put another class:

public class XMLParsingExample {
    private static String[] RssString;
/** Create Object For SiteList Class */
SitesList sitesList = null;

/** Called when the activity is first created. */

/** Create a new textview array to display the results */
String[] title;
String[] link;
String[] pubDate;
{
try {

/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();

/** Send URL to parse XML Tags */
URL sourceUrl = new URL(
"http://www.blich.co.il/rss.xml");

/** Create handler to handle XML Tags ( extends DefaultHandler ) */
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));

} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}

/** Get result from MyXMLHandler SitlesList Object */
sitesList = MyXMLHandler.sitesList;

/** Assign textview array lenght by arraylist size */
title = new String[sitesList.getTitle().size()];
link = new String[sitesList.getTitle().size()];
pubDate = new String[sitesList.getTitle().size()];

/** Set the result text in textview and add it to layout */
RssString=new String[sitesList.getItem().size()/2];
for (int i=0;i<RssString.length;i++)
    RssString[i]="";
int counter=1;
for (int i = 0; i < sitesList.getItem().size(); i++) {
    if (i%2!=0) {
title[i-counter]=sitesList.getTitle().get(i);
if (title[i-counter]!=null)
    RssString[i-counter]+=title[i-counter]+"~";
link[i-counter]=sitesList.getLink().get(i);
if (link[i-counter]!=null)
    RssString[i-counter]+=link[i-counter]+"~";
pubDate[i-counter]=sitesList.getPubDate().get(i);
if (pubDate[i-counter]!=null)
    RssString[i-counter]+=pubDate[i-counter]+"~";
counter++;
    }
}
}
public static String[] getRSSarray() {
    return RssString;
}
}

I gave you all the codes so you can see everything.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:36:53+00:00Added an answer on May 26, 2026 at 1:36 am

    Maybe what both of you told me would work, but it would be complicated.
    I have found an easier and more simple solution:
    Other parser.
    It uses 1 class (vs the sax parser that uses 3 classes), much much easier to understand, and of course, doesn’t ignore quotation marks 😀
    Thanks anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
i got an object with contents of html markup in it, for example: string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.