通过多个条件选择单个xmlNode [英] Selecting single xmlNode by multiple conditions

查看:67
本文介绍了通过多个条件选择单个xmlNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面有一个xml文件.我想通过检查两个条件从此数据中选择1条记录,为此,我在vb.net中编写了这样的查询

I have an xml file on below. I want to select 1 record from this data by checking two condition, for this I write a query in vb.net like this

Dim nod As XmlNode = xd.SelectSingleNode("/Table/Record[TXN_CODE='" & tbxTxnCode.Text & "']")


它工作正常,但是当我尝试添加其他条件时,它将引发错误,指出无效的令牌xpath异常
错误代码


It works fine but when I try to add the other condition it throws an error saying invalid token xpath exception
ERRROR CODE

Dim enodE As XmlNode = xd.SelectSingleNode("/Table/Record[TXN_CODE='MRV'] AND [DOC_NO = 1002]")


我尝试了几乎所有的组合,例如


I tried almost every combination like

Dim enodE As XmlNode = xd.SelectSingleNode("/Table/Record[TXN_CODE='MRV'] , [DOC_NO = 1002]") 
Dim enodE As XmlNode = xd.SelectSingleNode("/Table/Record[TXN_CODE='MRV' AND DOC_NO = 1002]") 
Dim enodE As XmlNode = xd.SelectSingleNode("/Table/Record[TXN_CODE='MRV' ,DOC_NO = 1002]")


任何人都有一个主意

MRV
1002
764
QQQ
KRV
1003
868
ASD


Anybody have an Idea

MRV
1002
764
QQQ
KRV
1003
868
ASD

推荐答案

我不了解XPath就不了解XPath.因此,我给出了有关将XPath与c#一起使用的一般链接

使用XPath和XmlDocument(C#)操纵XML数据 [ http://support.microsoft.com/kb/308333 [ http://support.microsoft.com/kb/308343 [
I don''t know the XPath without seeing your XML. So I give general links about using XPath with c#

Manipulate XML data with XPath and XmlDocument (C#)[^]

http://support.microsoft.com/kb/308333[^]

http://support.microsoft.com/kb/308343[^]


完全尝试一下这个
Try this one exactly
"/Table/Record[TXN_CODE=''MRV'' and DOC_NO = ''1002'']"


如果这不起作用,请删除1002&的引号.检查.

如果仍然不起作用,请尝试此操作.这可能不正确


if this doesn''t work, remove the quotes for 1002 & check.

If it still does not work, try this. This may not be right

"/Table/Record[TXN_CODE=''MRV''] | /Table/Record[DOC_NO = 1002]"


我认为这将选择TXN_CODE =''MRV''和DOC_NO = 1002的所有元素


I think this will select all elements with TXN_CODE=''MRV'' AND DOC_NO=1002


我碰巧连接了您之前的方法.

这是我使用的VB版本:

I happened to concatenate the way you did earlier.

here is the VB version that i used :

singleNode = element.SelectSingleNode("//Item[Slide = '" & appliesTo & "'" & _
                                                         "and ShapeName='" & lazName & "']/Language[@id='" & language & "']")



其中Item是一个以Slide和ShapeName作为其子节点的节点.

这是使用此工具进行转换后的C#版本.
http://www.developerfusion.com/tools/convert/vb-to-csharp/ [ ^ ]是:



where Item is a node with Slide and ShapeName as its child nodes.

Here is C# version after converting using this tool http://www.developerfusion.com/tools/convert/vb-to-csharp/[^] is :

singleNode == element.SelectSingleNode("//Item[Slide = '" + appliesTo + "'" + "and ShapeName='" + lazName + "']/Language[@id='" + language + "']")



希望能有所帮助! :)



Hope it helped! :)


这篇关于通过多个条件选择单个xmlNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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