简体   繁体   English

与元素类型“脚本”关联的属性名称“异步”后必须带有“ =”字符

[英]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.

相关问题 与元素类型“Hello”关联的属性名称“from”必须后跟“=”字符。 - 阿帕奇骆驼 - Attribute name “from” associated with an element type “Hello” must be followed by the ' = ' character. - Apache Camel 与元素类型“ null”相关联的属性“ href”的值不得包含“ &lt;”字符 - The value of attribute “href” associated with an element type “null” must not contain the '<' character 为什么显示元素类型“ bean”必须后面跟属性说明“&gt;”或“ /&gt;”。 <property name=“list”> - Why is it showing Element type “bean” must be followed by either attribute specifications, “>” or “/ >”.at <property name=“list”> 错误:与元素类型“FrameLayout”关联的属性“xmlns:tools”的值不得包含“&lt;”字符 - Error: The value of attribute "xmlns:tools" associated with an element type "FrameLayout" must not contain the '<' character org.xml.sax.SAXParseException:与元素类型“ Employee”相关联的属性“ id”的值不得包含“ &lt;”字符。 在 - org.xml.sax.SAXParseException: The value of attribute “id” associated with an element type “Employee” must not contain the '<' character. at 与元素类型“字符串”关联的属性“可翻译”的值不能包含“&lt;”字符。 错误 - The value of attribute “translatable” associated with an element type “string” must not contain the '<' character. error 元素类型“ Resource”之后必须是属性说明“&gt;”或“ /&gt;” - Element type “Resource” must be followed by either attribute specifications, “>” or “/>” SAXParseException:元素类型“ CountryNamecode”后必须跟随属性规范“&gt;”或“ /&gt;” - SAXParseException: Element type “CountryNamecode” must be followed by either attribute specifications, “>” or “/>” 元素类型“provider”必须后跟属性规范,“&gt;”或“/&gt;” - Element type “provider” must be followed by either attribute specifications, “>” or “/>” Spring 3拦截器错误:类型元素类型“ beans”之后必须是属性说明“&gt;”或“ /&gt;” - Spring 3 Interceptors Error: Type Element type “beans” must be followed by either attribute specifications, “>” or “/>”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM