XML 结束标签名称必须与 XML 结束标签名称完全匹配吗?
Must XML end tag names match XML end tag names exactly?
我有以下XML(测试示例):
<?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:Data' start tag on line 12 position 14 does not match the end tag of 'Data'. Line 12, position 43.
虽然 W3C 文档中的所有示例都显示命名空间限定的结束标记,但 MS Excel 打开此类文件时没有任何警告。
设置DataSet.Namespace = "ss";
不会改变任何东西。
如何读取此类文件,最好不添加额外的库?
是的,XML 结束标签必须与 XML 开始标签完全匹配,包括任何命名空间前缀。
根据你的问题:
What can be done to read such file, preferably without adding extra
libraries?
如果要使用兼容的 XML 工具成功解析 XML,则必须将其修复为格式正确。特别是,您必须将结束标记更改为 :</ss:Data>
根据 W3C XML Recommendation, section 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:]
根据你的问题:
While all examples in W3C documentation show namespace-qualified end
tags, MS Excel opens such file without any warnings.
然后 MS Excel 没有以合规的方式处理 XML,并且很可能遗漏了其他问题。
另见
我有以下XML(测试示例):
<?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:Data' start tag on line 12 position 14 does not match the end tag of 'Data'. Line 12, position 43.
虽然 W3C 文档中的所有示例都显示命名空间限定的结束标记,但 MS Excel 打开此类文件时没有任何警告。
设置DataSet.Namespace = "ss";
不会改变任何东西。
如何读取此类文件,最好不添加额外的库?
是的,XML 结束标签必须与 XML 开始标签完全匹配,包括任何命名空间前缀。
根据你的问题:
What can be done to read such file, preferably without adding extra libraries?
如果要使用兼容的 XML 工具成功解析 XML,则必须将其修复为格式正确。特别是,您必须将结束标记更改为 </ss:Data>
根据 W3C XML Recommendation, section 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:]
根据你的问题:
While all examples in W3C documentation show namespace-qualified end tags, MS Excel opens such file without any warnings.
然后 MS Excel 没有以合规的方式处理 XML,并且很可能遗漏了其他问题。
另见