[英]Attribute name “async” associated with an element type “script” must be followed by the ' = ' character
I am try to parse XML from existing URL. 我尝试从现有URL解析XML。
URL address: http://www.sozcu.com.tr/2016/yazarlar/ugur-dundar/rss 网址: 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 还有我的getXMLAttributeValue方法
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. 我也在Google中搜索它,但找不到任何解决方案。如何解决此问题。
Thanks. 谢谢。
They block or redirect clients that use default java user agent properties(something like: Java/1.8.0_71). 它们阻止或重定向使用默认Java用户代理属性(例如Java / 1.8.0_71)的客户端。 Add your own user agent and it works just fine:
添加您自己的用户代理,它可以正常工作:
DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
URLConnection uc = url.openConnection();
uc.setRequestProperty("User-Agent", "Karayel's rss reader");
Document document = (Document) dBuilder.parse(uc.getInputStream());
Parsing feeds manually is tedious and error prone(your getXMLAttributeValue
method throws NullPointerExceptions). 手动解析提要很繁琐且容易出错(您的
getXMLAttributeValue
方法抛出NullPointerExceptions)。 I suggest you use something like rometools instead. 我建议您改用rometools之类的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.