XML结束标记名称是否必须与XML结束标记名称完全匹配? [英] Must XML end tag names match XML end tag names exactly?

查看:662
本文介绍了XML结束标记名称是否必须与XML结束标记名称完全匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XML(测试示例):

I have the following XML (test example):

<?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" >
<Styles>
<Style ss:ID="s21"><NumberFormat ss:Format="@"/></Style>
</Styles>
<Worksheet ss:Name="--">
<Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1" x:FullRows="1" ss:StyleID="s21">
    <Column ss:StyleID="s21" ss:Width="184"/>
    <Row>   
        <Cell><ss:Data ss:Type="String">42</Data></Cell>
</Row></Table></Worksheet></Workbook>

尝试使用 DataSet.ReadXml(),则会生成以下异常: The ss第12行位置14上的:Data'开始标记与'Data'的结束标记不匹配。第12行,位置43。

W3C文档中的所有示例都显示了名称空间限定的结束标记,而MS Excel会在没有任何警告的情况下打开此类文件。

When trying to read the file using DataSet.ReadXml(), the following exception is generated: The 'ss:Data' start tag on line 12 position 14 does not match the end tag of 'Data'. Line 12, position 43.
While all examples in W3C documentation show namespace-qualified end tags, MS Excel opens such file without any warnings.

设置 DataSet.Namespace = ss; 不会更改任何内容。

Setting DataSet.Namespace = "ss"; doesn't change anything.

如何读取此类文件,最好不添加额外的库?

What can be done to read such file, preferably without adding extra libraries?

推荐答案

是的,XML结束标记必须与XML开始标记完全匹配,包括任何名称空间前缀。

根据您的问题:


如何读取此类文件,最好不添加额外的
库?

What can be done to read such file, preferably without adding extra libraries?

如果要使用兼容的XML工具成功解析XML,必须对其进行修复以使其格式正确。特别是,您必须将结束标签更改为 @jdweng在评论中建议< / ss:Data>

The XML must be repaired to be well-formed if it's to be parsed successfully using compliant XML tools. In particular, you must change the the end-tag as @jdweng suggests in the comments: </ss:Data>

W3C XML建议,第3.1节


[定义:每个以起始标记
开头的元素的结尾都必须标记结束标记包含与开始标记中给出的
元素类型相呼应的名称:]

[Definition: The end of every element that begins with a start-tag must be marked by an end-tag containing a name that echoes the element's type as given in the start-tag:]

来自您的问题:


虽然W3C文档中的所有示例都显示了名称空间限定的
标签,但是MS Excel会在没有任何警告的情况下打开此类文件。

While all examples in W3C documentation show namespace-qualified end tags, MS Excel opens such file without any warnings.

然后,MS Excel无法以兼容的方式处理XML,很可能会丢失o这些问题。

Then MS Excel isn't processing the XML in a compliant manner and may well be missing other issues.

另请参见如何解析无效(格式错误/格式错误)的XML?

这篇关于XML结束标记名称是否必须与XML结束标记名称完全匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆