以XML值读取空间. [英] Reading space in XML value.

查看:73
本文介绍了以XML值读取空间.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个XML文件,其中包含一些带有节点空格的值.当我尝试从VC ++读取valeu时,得到的值没有空格.如何在不删减空格的情况下读取完整值.

XML文件示例:

Hi,

I have a XML file which contains some values with sapace for a node. When i am trying to read the valeu from VC++ I am getting the values without the space. How can I read the complete value without getting the spaces trimmed off.

Example of XML file:

<Parameter>
    <ParameterName>UserOptions/OperatingSystemSettings/Password</ParameterName>
    <ParameterValue> sudhir </ParameterValue>
</Parameter>


在上面的XML中,请观察值sudhir的开头和结尾处的空格.下面是我必须读取值的代码.


In above XML observe the space at the beginning and the end of the value sudhir. Below is the code I have to read the value.

hr = ((MSXML2::IXMLDOMElement*)objXmlNode)->getElementsByTagName(strParameterValueNode)->Getitem(0)->get_text(&strParameterValue);


请让我知道是否有人知道如何读取完整的值.

问候,
Sudhir


Please let me know if any one knows how to read the complete values.

Regards,
Sudhir

推荐答案

这篇文章是Stackoverflow的引文: ^ ].

假设您正在使用XmlDocument,则应设置 PreserveWhiteSpace 属性设置为True.如果使用和XmlReader,则将有关在序列化时保留空白的MSDN文章.不同的序列化器以不同的方式处理,请尝试使用 XmlTextReader 为此,按照描述 [
This post is a quote from Stackoverflow: http://stackoverflow.com/questions/1927006/in-c-how-to-get-xml-node-value-that-is-white-space[^].

"Assuming you are using XmlDocument, you should set the PreserveWhiteSpace property to True. If using and XmlReader set the WhitespaceHandling property WhitespaceHandling.All. See this MSDN article about Preserving White Space While Serializing. The different serializers handle this different ways, try using the XmlTextReader for this, as per this forum post.

Original poster: Oded[^]
Best Regards,

—MRB


您只需要将prepareWhiteSpace设置为true.检查链接以获取更多信息:
http://msdn.microsoft.com/en-us/library/ms761353%28v = vs.85%29.aspx#Y342 [
You just need to set the preserveWhiteSpace to true. Check the link for more info:
http://msdn.microsoft.com/en-us/library/ms761353%28v=vs.85%29.aspx#Y342[^]

Good luck!


这篇关于以XML值读取空间.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆