VB.NET:XPath 问题
我有以下 XML:
<?xml version="1.0" encoding="utf-8" ?>
<configuracoes>
<gerais>
<atualizacoes>
<tipo>automática</tipo>
<frequencia>diária</frequencia>
</atualizacoes>
</gerais>
</configuracoes>
和代码:
Dim xPathNavigator As XPathNavigator
Dim xPathNodeIterator As XPathNodeIterator
xPathNavigator = Me.XML.CreateNavigator()
xPathNodeIterator = xPathNavigator.Select("/configuracoes/gerais/atualizacoes")
While (xPathNodeIterator.MoveNext())
Dim xPathNavigatorInterno As XPathNavigator = xPathNodeIterator.Current
MsgBox(xPathNavigatorInterno.Value) 'It Shows "automáticadiária" instead of "automática" and then "diária" in the next iteration...
End While
我想进入第一个迭代“automática”,然后进入最后一个迭代“diária”。怎么了?我该如何解决这个问题?谢谢。
I have the follwing XML:
<?xml version="1.0" encoding="utf-8" ?>
<configuracoes>
<gerais>
<atualizacoes>
<tipo>automática</tipo>
<frequencia>diária</frequencia>
</atualizacoes>
</gerais>
</configuracoes>
And the code:
Dim xPathNavigator As XPathNavigator
Dim xPathNodeIterator As XPathNodeIterator
xPathNavigator = Me.XML.CreateNavigator()
xPathNodeIterator = xPathNavigator.Select("/configuracoes/gerais/atualizacoes")
While (xPathNodeIterator.MoveNext())
Dim xPathNavigatorInterno As XPathNavigator = xPathNodeIterator.Current
MsgBox(xPathNavigatorInterno.Value) 'It Shows "automáticadiária" instead of "automática" and then "diária" in the next iteration...
End While
I want to get in the first iteration "automática" and then, in the last one "diária". What's wrong? How could I solve that? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
节点的
Value
始终是所有后代文本节点的串联值。这类似于 HTML,其中 的值为“这是一些粗体文本。”
。如果您需要单独的值,请明确选择单独的节点。就您而言,由于它们具有不同的名称,因此我使用了
*
。Try
The
Value
of a node always is the concatented value of all descendant text nodes. This is analoguous to HTML, where the value ofis
"This is some bold text."
.If you want the indiviual values, select the individual nodes explicitly. In your case, since they have different names, I used the
*
.前进的另一个考虑因素是使用 LINQ to XML 而不是 XPath。根据我的经验,通过查询使用和导航 XML 比像 XPath 那样迭代它要容易得多。为了供将来参考,请查看下面的链接:
Visual Basic 中的 LINQ to XML 概述:
http://msdn.microsoft.com/en-us/library/bb384460。 ASPX
Another consideration moving forward is to use LINQ to XML rather than XPath. In my experience it is much easier to use and navigate XML via queries than iterating through it like XPath does. For future reference take a look at the link below:
Overview of LINQ to XML in Visual Basic:
http://msdn.microsoft.com/en-us/library/bb384460.aspx