XmlTextReader,解析,空间作为数据

编程入门 行业动态 更新时间:2024-10-09 21:28:18
本文介绍了XmlTextReader,解析,空间作为数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我刚碰过这个。 #1< DBColumn> 1< / DBColumn> #2< DBColumn> < / DBColumn> #1的数据将被解析并返回为 1。我得到一个 元素/文本/结束元素的序列。 不会返回#2的数据。我得到一个 元素/空格/结束元素的序列。 为什么我的开始和结束标记之间的数据(恰好是空格) 被误解了? TIA

I just ran across this. #1 <DBColumn> 1 </DBColumn> #2 <DBColumn> </DBColumn> The data for #1 will be parsed and returned as " 1 ". I get a sequence of Element/Text/EndElement. The data for #2 will not be returned. I get a sequence of Element/Whitespace/EndElement. Why is the data (which happens to be spaces) between my start and end tags being misinterpreted? TIA

推荐答案

嗨Kenneth, 首先,我想确认一下我对你的问题的理解。从 您的描述中,我了解您需要在 Xml文档中保留空白。如果有任何误解,请随时告诉我 知道。 XmlTextReader仅保留在 $ b内发生的空白区域$ b xml:space =" preserve"上下文。因此,您需要将其添加到父节点,因为 是一个属性。如果您使用的是XmlDocument,则可以在调用Load或LoadXml方法之前将 PreserveWhitespace属性设置为true。 您可以查看以下链接以获取更多信息。 msdn.microsoft/library/de...us/cpguide/htm l / cpconHandlingWhiteSpaceWithXmlTextReader.asp Kevin Yu ======= 此帖子已提供按现状没有保证,并且不授予 权利。 Hi Kenneth, First of all, I would like to confirm my understanding of your issue. From your description, I understand that you need to preserve whitespace in your Xml document. If there is any misunderstanding, please feel free to let me know. The XmlTextReader only preserves white space that occurs within an xml:space="preserve" context. So you need to add it to the parent node as an attibute. If you''re using an XmlDocument, you can simply set PreserveWhitespace property to true before calling Load or LoadXml method. You can check the following link for more information. msdn.microsoft/library/de...us/cpguide/htm l/cpconHandlingWhiteSpaceWithXmlTextReader.asp Kevin Yu ======= "This posting is provided "AS IS" with no warranties, and confers no rights."

Kevin, 我只想要数据元素中的空格("),而不是元素之间的空格。 当我的数据中包含非空格字符时,将检索空间数据。 /> 如果我只有一个或多个空格,它会被写入XML而不会被拔出。 #1< DBColumn> 1< / DBColumn> < ---检索空格 我得到一个Element / Text / EndElement序列。 #2< DBColumn> < / DBColumn> < ---只是空格,没有数据 检索 我得到一系列Element / Whitespace / EndElement。 " Kevin Yu [MSFT] QUOT;写道: Kevin, I only want the space (" ") within a data element, not between elements. When my data has a non-space character in it, the space data is retrieved. If I just have one or more spaces it gets written to XML but not pulled out. #1 <DBColumn> 1 </DBColumn> <--- spaces retrieved I get a sequence of Element/Text/EndElement. #2 <DBColumn> </DBColumn> <--- just spaces, no data retrieved I get a sequence of Element/Whitespace/EndElement. "Kevin Yu [MSFT]" wrote: 嗨Kenneth, 首先,我想确认一下我对你的问题的理解。从您的描述中,我了解您需要在您的 Xml文档中保留空白。如果有任何误解,请随时告诉我 XmlTextReader仅保留在 xml:space =" preserve"内发生的空白区域。上下文。因此,您需要将其添加到父节点作为属性。如果您使用的是XmlDocument,则可以在调用Load或LoadXml方法之前将 PreserveWhitespace属性设置为true。您可以查看以下链接以获取更多信息。 http:// msdn .microsoft / library / de ... us / cpguide / htm l / cpconHandlingWhiteSpaceWithXmlTextReader.asp Kevin Yu ======= 这个帖子是按原样提供的没有保证,也没有授予权利。 Hi Kenneth, First of all, I would like to confirm my understanding of your issue. From your description, I understand that you need to preserve whitespace in your Xml document. If there is any misunderstanding, please feel free to let me know. The XmlTextReader only preserves white space that occurs within an xml:space="preserve" context. So you need to add it to the parent node as an attibute. If you''re using an XmlDocument, you can simply set PreserveWhitespace property to true before calling Load or LoadXml method. You can check the following link for more information. msdn.microsoft/library/de...us/cpguide/htm l/cpconHandlingWhiteSpaceWithXmlTextReader.asp Kevin Yu ======= "This posting is provided "AS IS" with no warranties, and confers no rights."

嗨肯, 我担心这是XmlTextReader的设计。如果我们在元素中没有任何 上下文,那么如果我们没有空格就会被放弃 xml:space =" preserve"元素中的属性集。请查看我在上一篇文章中发布的MSDN 文档以获取更多信息。谢谢! Kevin Yu ======= 此帖子已提供按原样没有保证,也没有赋予 权利。 Hi Ken, I''m afraid this is by design for the XmlTextReader. If we don''t have any context within an element the whitespaces are abandoned if we don''t have xml:space="preserve" attribute set in the element. Please check the MSDN document I posted in my last post for more information. Thanks! Kevin Yu ======= "This posting is provided "AS IS" with no warranties, and confers no rights."

更多推荐

XmlTextReader,解析,空间作为数据

本文发布于:2023-11-28 20:28:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643844.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   空间   XmlTextReader

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!