Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing when element is between buffers #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions library/src/main/java/me/toptas/rssconverter/XMLParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class XMLParser extends DefaultHandler {
private boolean mParsingTitle = false;
private boolean mParsingDescription = false;
private boolean mParsingLink = false;
private boolean mParsingSpecialValue = false;

private String mElementValue = null;
private String mTitle = sEmptyString;
Expand Down Expand Up @@ -67,6 +68,11 @@ public void startElement(String uri, String localName, String qName,
mLink = sEmptyString;
}
break;
case sPublishDate:
case sUrl:
case sImage:
mParsingSpecialValue = true;
break;
}
/*if (localName.equals(sItem)) {
mRssItem = new RssItem();
Expand Down Expand Up @@ -125,12 +131,16 @@ public void endElement(String uri, String localName, String qName)
break;
case sImage:
case sUrl:
mParsingSpecialValue = false;
if (mElementValue != null && !mElementValue.isEmpty()) {
mImage = mElementValue;
mElementValue = sEmptyString;
}
break;
case sPublishDate:
mParsingSpecialValue = false;
mDate = mElementValue;
mElementValue = sEmptyString;
break;
case sDescription:
mParsingDescription = false;
Expand All @@ -145,6 +155,10 @@ public void endElement(String uri, String localName, String qName)
public void characters(char[] ch, int start, int length)
throws SAXException {
String buff = new String(ch, start, length);
if (mParsingSpecialValue) {
mElementValue = mElementValue + buff;
return;
}
if (mElementOn) {
if (buff.length() > 2) {
mElementValue = buff;
Expand Down