I am try to parse XML from existing URL.
URL address: http://www.sozcu.com.tr/2016/yazarlar/ugur-dundar/rss
try {
URL url = new URL(urlAddress);
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
InputSource ıo = new InputSource(url.openStream());
Document document = (Document) dBuilder.parse(ıo);
document.getDocumentElement().normalize();
NodeList nodeList = document.getElementsByTagName("item");
for (int i = 0; i < nodeList.getLength(); i++) {
Node node = nodeList.item(i);
Element mainElement = (Element) node;
String link = getXMLAttributeValue("link", mainElement);
String title = getXMLAttributeValue("title", mainElement);
String desc = getXMLAttributeValue("desc",mainElement);
sozcuArticle.add(new Sozcu(link, title, desc));
}
} catch (ParserConfigurationException | IOException | SAXException ex) {
System.out.println(ex.getMessage());
}
Also my getXMLAttributeValue method
public String getXMLAttributeValue(String tag, Element element) {
NodeList nodeElement = element.getElementsByTagName(tag);
Element Element = (Element) nodeElement.item(0);
return Element.getChildNodes().item(0).getNodeValue();
}
When I run the program.I am getting exception.
[Fatal Error] :51:119: Attribute name "async" associated with an element type "script" must be followed by the ' = ' character.
Attribute name "async" associated with an element type "script" must be followed by the ' = ' character.
[Fatal Error] :5:409: Element type "n.length" must be followed by either attribute specifications, ">" or "/>".
Element type "n.length" must be followed by either attribute specifications, ">" or "/>".
I also search it in google but I can't find any solution.How can I fix this problem.
Thanks.