English 中文(简体)
XML 解析错误: UTF-8
原标题:XML parsing error: UTF-8

我试图将 XML 文件( 带有“ NDS” 扩展名) 作为数据读入我的 Android 应用程序。 我选择使用 DOM DocumentBilder 路径, 称之为其分析方法 。

问题在于节点名称之一中存在非 ASCII delta () 字符。 这导致分析操作以 DOM 例外方式失败。 我解开违规线时, 它有效 。

我用.NET 库方法在 Windows 下创建的 XML 文件, 它有 < code_ lt;? xml 版本= "1.0" 编码= "utf-8"? & gt; 。 (我还注意到此页头前面有 3 byte BOM 。 )

犯罪线周围的XML等级结构 看起来像

<?xml version="1.0" encoding="utf-8"?>
<NDS SoftwareIdentity="MicroAnalyzer 2000" SoftwareVersion="3.5.8" WindowsVersion="Microsoft Windows NT 5.1.2600 Service Pack 3" CLRVersion="2.0.50727.3615" MachineName="SYSTEM2000_3033" MachineDescription="" DataSource="System2000_3033SQLEXPRESS" Date="3/31/2012" Time="11:15 AM">
    <ASME_B46_1_2002DataSet xmlns="http://tempuri.org/ASME_B46_1_2002DataSet.xsd">
        <ASME_B46_1_2002RoughnessInstanceTable>
            <InstanceAppendixId>-1</InstanceAppendixId>
            <RΔaEnabled>false</RΔaEnabled>
        </ASME_B46_1_2002RoughnessInstanceTable>
    </ASME_B46_1_2002DataSet>
</NDS>

你会认为在 UTF-8 下三角洲字符是可以接受的, 事实上这个 XML 由 Internet Explorer 正确解释 。

问题回答

http://www.w3.org/TR/REC-xml/#NT-NameChar” rel=“nofollow”>http://www.w3.org/TR/REC-xml/#NT-NameChar

[4]     NameStartChar      ::=      ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]


[4a]    NameChar       ::=      NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]

有在 XML 1. 0 中有效的 Unicode 字符, 但不是全部。 您的字符 (# x394) 是一个有效的 nameStartChar, 和 范围 [# x37F-# x1FFF] 一样 。

我相信 XML 1.0 要求元素和属性名称只包含 ASCII 字符( 一些非打印的 ASCII 字符被禁止 ) 。 声明 UTF-8 编码允许非 ASCII 字符出现在元素和属性的 中 。

XML 1. 1. 1 放宽了这一限制,允许 Unicode 、非 ASCII 字符在元素和属性名称中出现。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...