You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.7 KiB

package ru.defend.defdevteam.tstu;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import java.util.ArrayList;
import java.util.Collection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
/**
* Created by thedefend on 29.11.16.
*/
public class FeedParser {
ParserCallback callback;
NewsItemList newsItemList;
String inputXML;
interface ParserCallback {
void onSuccessParsing(NewsItemList newsItemList);
void onFailureParsing();
}
void registerCallback(ParserCallback callback) {
this.callback = callback;
}
FeedParser(String inputXML) {
newsItemList = new NewsItemList();
this.inputXML = inputXML;
}
void parseXML() {
NewsItemList.Group group = new NewsItemList().new Group(); // <---Remove that
try {
DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
// Создается дерево DOM документа из файла
Document document = documentBuilder.parse(inputXML);
// Получаем корневой элемент
Node root = document.getDocumentElement();
String exp = root.getTextContent(); // <---Remove that
group.set("Node",exp,""); // <---Remove that
newsItemList.add(group);// <---Remove that
} catch (Exception e) {
e.printStackTrace();
}
group.set("Node2","end",""); // <---Remove that
newsItemList.add(group);// <---Remove that
group.set("Node3","2end",""); // <---Remove that
newsItemList.add(group);// <---Remove that
callback.onSuccessParsing(newsItemList);
}
}