java - 字符序列 "]]>"不得出现在内容中,除非用于标记 CDATA 部分的结尾

标签 java xml cdata

  1. 我有来自 url 的 xml。
  2. xml结构如下:

    <?xml version="1.0" encoding="utf-8"?><xml><root>
    <row>
    <company><![CDATA[  ]]></company>
    <id>10331</id>
    <account></account>
    <terms> </terms>
    <level>standard</level>
    <location><![CDATA[  ]]></location>
    <booth></booth>
    <contractor></contractor>
    <address>
    <country></country>
    <street><![CDATA[  ]]></street>
    <city></city>
    <state></state>
    <zip></zip>
    </address>
    <description><![CDATA[  ]]></description>
    </row>
    <row>
    <company><![CDATA[  ]]></company>
    <id>9644</id>
    <account></account>
    <terms> </terms>
    <level>standard</level>
    <location><![CDATA[  ]]></location>
    <booth></booth>
    <contractor></contractor>
    <address>
    <country></country>
    <street><![CDATA[  ]]></street>
    <city></city>
    <state></state>
    <zip></zip>
    </address>
    <description><![CDATA[  ]]></description>
    </row>
    <row>
    <company><![CDATA[  ]]></company>
    <id>9650</id>
    <account></account>
    <terms> </terms>
    <level>standard</level>
    <location><![CDATA[  ]]></location>
    <booth></booth>
    <contractor></contractor>
    <address>
    <country></country>
    <street><![CDATA[  ]]></street>
    <city></city>
    <state></state>
    <zip></zip>
    </address>
    <description><![CDATA[  ]]></description>
    </row>
    <row>
    <company><![CDATA[ 3-CI ]]></company>
    <id>780</id>
    <account>001F000000qM0KkIAK</account>
    <terms> </terms>
    <level>standard</level>
    <location><![CDATA[ Hall F ]]></location>
    <booth>8215</booth>
    <contractor>Goodkey</contractor>
    <url><![CDATA[ http://www.3ci.com ]]></url>
    <address>
    <country>Canada</country>
    <street><![CDATA[ 18, 5555 51st Ave SE ]]></street>
    <city>Calgary</city>
    <state>Alberta</state>
    <zip>T2C 3X4</zip>
    </address>
    <phone>(403) 250-2271 X102</phone>
    <email>colin@3-ci.com</email>
    <description><![CDATA[ 3CI is an Overmold Connectivity Solutions Provider for signal cables, power cables, harnesses and custom solutions for industry.
    
    Manufactured in Canada , we are a privately held ISO 9001:2008 accredited company with over 15 years experience in Oil and Gas, Military, Shipboard, Transit/Heavy Equipment, Light Rail ,Mining, Sanding and Salting machinery.
    
    The concept is to solve environmental issues in the wire and cable industry. The opportunity is to reduce overhead costs and increase product reliability. The potential is to eliminate failure and reduce overall cost in any application.
    
    &nbsp;
    
    With our own fully machined and staffed machine shop we are able to add value to all our customer's needs by way of the ability to create molds in house , and components used in our manufacturing , not to mention full on machining capability providing a complete manufacturing solution for over-molded wire and cable , parts , panels and much much more. ]]></description>
    </row>
    <row>
    <company><![CDATA[ 3M ]]></company>
    <id>4090</id>
    <account></account>
    <terms> </terms>
    <level>standard</level>
    <location><![CDATA[  ]]></location>
    <booth></booth>
    <contractor></contractor>
    <url><![CDATA[ http://www.3mcanada.ca/3M/en_CA/country-ca/ ]]></url>
    <address>
    <country></country>
    <street><![CDATA[  ]]></street>
    <city></city>
    <state></state>
    <zip></zip>
    </address>
    <phone></phone>
    <email></email>
    <description><![CDATA[  ]]></description>
    </row>
    <row>
    <company><![CDATA[ 3M Canada Company ]]></company>
    <id>782</id>
    <account>001F000000qLn9lIAC</account>
    <terms><term><![CDATA[Abrasion and Corrosion Control]]></term><term><![CDATA[Filters - Air, Gas and Liquids]]></term><term><![CDATA[Fire Protection - Equipment and Services]]></term><term><![CDATA[Health and Safety - Equipment and Systems]]></term><term><![CDATA[Health and Safety - Fall Protection]]></term><term><![CDATA[Filters]]></term><term><![CDATA[Fire Protection]]></term><term><![CDATA[Health and Safety]]></term> </terms>
    <level>standard</level>
    <location><![CDATA[ Halls A, B, C ]]></location>
    <booth>1110</booth>
    <contractor>Goodkey</contractor>
    <url><![CDATA[ http://www.3m.ca/oilandgas ]]></url>
    <address>
    <country>Canada</country>
    <street><![CDATA[ 1001 53RD AVE N.E. ]]></street>
    <city>Calgary </city>
    <state>Alberta </state> 
    <zip>T2E 7K4</zip>
    </address>
    <phone>780-235-8283</phone>
    <email>jboychuk@mmm.com</email>
    <description><![CDATA[ 3M supplies thousands of products to the global Oil and Gas Industry and its applications. From everyday essentials – such as respirators, abrasives and electrical connectors – to advanced materials for preventing corrosion and reducing the density of down hole cements, 3M technologies offer you a wealth of ingenious solutions to many of today's toughest challenges. ]]></description>
    </row>........................................
    
  3. 当我从 url 读取它时,它给了我异常,就像在解析期间一样,因为 cdata 中缺少数据:

    [Fatal Error] exhibitors-feed123.xml:18125:5: The character sequence "]]>" must not appear in content unless used to mark the end of a CDATA section.

    <row>
            <company><![CDATA[ Kaeser Compressors Inc. ]]></company>
            <id>1416</id>
            <account>001F000000qM0y3IAC</account>
                    <terms>            </terms>
            <level>standard</level>
            <location><![CDATA[ Halls D, E ]]></location>
            <booth>7752</booth> 
            <contractor>Goodkey</contractor> 
    
            <url><![CDATA[ http://www.kaeser.com ]]></url>
                        <address>
                <country>Canada</country>
                <street><![CDATA[ 3760 rue La Verendrye ]]></street>
                <city>Boisbriand</city>
                <state>Quebec</state>
                <zip>J7H 1H5</zip>
            </address>
    
                <phone>(450) 971-1414</phone>
    
                <email>christine.shipley@kaeser.com</email>
                        <description><![CDATA[  ]]></description>
        </row> 
    
    
        <row>
            <company><![CDATA[ Kaizen Institute Canada ]]></company>
            <id>3694</id>
            <account>001F0000014MuChIAK</account>
                    <terms><term><![CDATA[Consultants]]></term><term><![CDATA[Consultants - Other]]></term>            </terms>
            <level>standard</level>
            <location><![CDATA[ Corral ]]></location>
            <booth>2222</booth> 
            <contractor>Superior</contractor> 
    
            <url><![CDATA[ http://ca.kaizen.com ]]></url>
                        <address>
                <country>Canada</country>
                <street><![CDATA[ 207 5720 Macleod Trail SW ]]></street>
                <city>Calgary</city>
                <state>Alberta</state>
                <zip>T2H 0J6</zip>
            </address>
    
                <phone>(403) 452-1795</phone>
    
                <email>ccherry@kaizen.com</email>
                        <description>as industry at the Heavy Oil Theater!
    
     ]]></description>
        </row> 
    

最佳答案

看起来问题是 XML 格式不正确。 xmlwf 实用程序说事实并非如此。它给出的错误是:

foo.xml:18135:65: not well-formed (invalid token)

错误不在您的代码中。您应该联系数据提供商并让他们修复 XML 生成问题。

关于java - 字符序列 "]]>"不得出现在内容中,除非用于标记 CDATA 部分的结尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34527569/

相关文章:

java - 用Java读取文件

java - 使用 gdata-android-2.2.1-alpha 检索 Google 日历列表

ruby - 让 Nokogiri 决定是否使用 #fragment 还是 #parse

javafx - 如何正确使用高对比度主题?

ios - XML 解析数据没有从 viewController 获取到 objective-c 中的 tableViewController?

xml - 如何在 xi :include of a XML file? 中使用环境变量

java - JAXB 拆解 cdata

special-characters - CDATA 代码块中的特殊字符

xml - XML 中的空 CDATA

java - 在程序启动时操作 Swing 组件的正确方法是什么?