空格上的XPathNavigator.SelectSingleNode(xpath)返回0长度s [英] XPathNavigator.SelectSingleNode(xpath) on space returns 0 length s
本文介绍了空格上的XPathNavigator.SelectSingleNode(xpath)返回0长度s的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨;
我有一个元素:
< space> < / space>
当我调用SelectSingleNode()时,InnerXml是一个0长度的字符串,而不是
a包含1个空格的字符串。 />
有什么想法吗?
-
谢谢 - 戴夫
Hi;
I have an element:
<space> </space>
When I call SelectSingleNode() on it, the InnerXml is a 0 length String, not
a String containing 1 space.
Any ideas?
--
thanks - dave
推荐答案
您好dave,
您可以将PreserveWhitespace设置为true,以便保留空间。
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.LoadXml("< space>< / space>");
XmlNode n = doc.SelectSingleNode(" space");
MessageBox.Show(n.InnerXml.Length.ToString());
HTH。
Kevin Yu
=======
"这个帖子是提供按原样没有保证,也没有赋予
权利。
Hi dave,
You can set PreserveWhitespace to true, so that the space will be preserved.
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.LoadXml("<space> </space>");
XmlNode n = doc.SelectSingleNode("space");
MessageBox.Show(n.InnerXml.Length.ToString());
HTH.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
嗨;
抱歉 - 我忘了提 - 我给人们的API是传递一个
XPathNavigator。所以它可能不是XmlDocument。即使它是,我没有
方式访问该对象。
如何为XPathNavigator执行此操作?
-
谢谢 - 戴夫
" Kevin Yu [MSFT]"写道:
Hi;
Sorry - I forgot to mention - the API I give people is to pass in a
XPathNavigator. So it may not be an XmlDocument. And even if it is, I have no
way of accessing that object.
How do I do this for an XPathNavigator?
--
thanks - dave
"Kevin Yu [MSFT]" wrote:
你好dave,
你可以将PreserveWhitespace设置为true,这样就可以保留空间。
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.LoadXml("< space>< / space>");
XmlNode n = doc.SelectSingleNode( space;;
MessageBox.Show(n.InnerXml.Length.ToString());
HTH。
Kevin Yu
= ======
此帖子是按原样提供的没有保证,也没有授予
权利。
Hi dave,
You can set PreserveWhitespace to true, so that the space will be preserved.
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.LoadXml("<space> </space>");
XmlNode n = doc.SelectSingleNode("space");
MessageBox.Show(n.InnerXml.Length.ToString());
HTH.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
嗨dave,
无法使用
XPathNavigator直接保留代码中的空格。您可以尝试执行以下操作:
1.添加whiteSpace ="保留"在标签中。 < space whiteSpace =" preserve">
< / space>
它必须是XPathNodeType.SignificantWhitespace或
XPathNodeType.Whitespace。
Kevin Yu
== =====
此帖子已提供按原样没有保证,也没有赋予
权利。
Hi dave,
There is no way to preserve whitespace in the code directly with
XPathNavigator. You can try to do the following:
1. Add whiteSpace="preserve" in the tag. <space whiteSpace="preserve">
</space>
2. If the node is a whitespace, check the XPathNavigator.NodeType property,
it has to be XPathNodeType.SignificantWhitespace or
XPathNodeType.Whitespace.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
这篇关于空格上的XPathNavigator.SelectSingleNode(xpath)返回0长度s的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文