在 .NET 3.5 中使用 XmlReader.ReadInnerXML 正确读取嵌套 XML 文档
我使用 XmlReader.ReadInnerXML 来读取嵌入在外部 XML 文档元素中的 XML 文档(作为文本)。除了内部 XML 属性中制表符的处理之外,此方法工作正常。示例:
<document>
<interface>
<scriptaction script="	one tab
		two tabs
			three tabs" />
</interface>
</document>
当在“文档”元素级别使用 ReadInnerXML 时,生成的字符串如下所示:
<interface><scriptaction script=" one tab
 two tabs
 three tabs"/></interface>
IOW,制表符将转换为实际的制表符字符。然后,当我们解析生成的内部文档时,制表符会按照通常的空白处理方式规范化为空格,结果是将制表符转换为空格。我们需要按原样保留属性值。
我们尝试了各种 XmlReader 设置,但没有成功。这可能是读者的缺陷,还是我们做错了什么?
提前致谢,
- 内森·艾伦 - 数据库咨询小组
I'm using an XmlReader.ReadInnerXML to read an XML document (as text) embedded within in an element of an outer XML document. This works fine except for the handling of tab characters in attributes of the inner XML. Example:
<document>
<interface>
<scriptaction script=" one tab
two tabs
three tabs" />
</interface>
</document>
When ReadInnerXML is used at the "document" element level, the resulting string looks like this:
<interface><scriptaction script=" one tab
two tabs
three tabs"/></interface>
IOW, the tabs are turned into actual tab characters. Then when we then parse the resulting inner document, the tabs are normalized into spaces in the usual whitespace handling fashon, and the result is the conversion of tab characters to spaces. We need to preserve the attribute values as they are.
We've tried messing with various XmlReader settings to no avail. Is this possibly a defect in the reader, or something we're doing wrong?
Thanks in advance,
--
Nathan Allan -
Database Consulting Group
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
恐怕 XML 规范需要这种行为: http://www. w3.org/TR/REC-xml/#AVNormalize
您控制 XML 生成吗?您可以使用 CDATA 部分来代替吗?
I'm afraid this behaviour is required by the XML spec: http://www.w3.org/TR/REC-xml/#AVNormalize
Do you control the XML generation? Can you use a CDATA section instead?