当空白不重要时,表示可能非常重要。在
在xmlschema第2部分:Datatypes第二版中,约束方面空白是为派生自string(http://www.w3.org/TR/xmlschema-2/#rf-whiteSpace)的类型定义的。如果这个空白方面是替换或折叠,则值可能在normalization期间更改。在
在Section 4.3.6结尾处有一个注释:
The notation #xA used here (and elsewhere in this specification) represents the Universal Character Set (UCS) code point hexadecimal A (line feed), which is denoted by U+000A. This notation is to be distinguished from 
, which is the XML character reference to that same UCS code point.
如果一个元素的数据类型有一个空白约束折叠,"<elem> text </elem>"
应该变成"text"
(删除了前导和尾随的空白),但是"<elem> text </elem>"
应该变成{
因此,要么由解析器/树生成器处理这种规范化,要么在之后完成。在
set_whitespace_normalization('./country/neighbor', 'collapse')
的东西?在normalize(content)
的钩子?在elem.original_text
,它可能返回“ text 
”?在elem.unnormalized_text
,它可能返回“text
”?在我想用Python的xml.etree.ElementTree但是,我将考虑其他任何可以完成这项工作的XML库。在
当然,声明空白无关紧要(替换或折叠)然后使用字符引用作弊,这是一种糟糕的风格。在大多数情况下,应该更改数据或模式来防止这种情况发生,但有时您必须处理外来的XML模式和外来XML文档。上面提到的注释的存在表明XML编辑器意识到了这一困境,并没有刻意阻止它。在
这似乎是xml.etree.ElementTree:http://bugs.python.org/issue17582。根据错误报告,这是正确处理的lxml.etree:https://pypi.python.org/pypi/lxml/。在
相关问题 更多 >
编程相关推荐