我必须解析一个xml,它有带有属性的xml元素,其值可以是带有空格和换行的多行。
我正在使用minidom进行解析,但是我得到的多行属性值没有换行。
如何使用minidom获得这样的值?如果不是minidom,其他哪个库支持这样的属性?
发布于 2018-12-26 14:26:13
这不是minidom或者别的什么的问题.它是XML标准,它告诉那个属性值。
对于空白字符(#x20,#xD,#xA,#x9),将空格字符(#x20)附加到规范化值中
https://www.w3.org/TR/2008/REC-xml-20081126/#attdecls
这意味着,您永远不会在XML属性值中找到\n (linefeed)、\r (回车)或\t (选项卡)字符,至少如果您的解析器遵循规则。
发布于 2018-12-26 14:26:27
根据XML-Spec - 3.3.3属性-值规范化,换行符是不允许的,并被空格所取代。
在将属性值传递给应用程序或检查其有效性之前,XML处理器必须通过应用下面的算法或使用其他方法将属性值规范化,以便传递给应用程序的值与该算法生成的值相同。
- For a character reference, append the referenced character to the normalized value.
- For an entity reference, recursively apply step 3 of this algorithm to the replacement text of the entity.
- For a **white space character** (#x20, **#xD, #xA,** #x9), append a space character (#x20) to the normalized value.
- For another character, append the character to the normalized value.
(强调地雷)
见打开"bug“ )
https://stackoverflow.com/questions/53933223
复制相似问题