如何检查来自protectionorder父节点的第一个状态元素是否等于来自mnprotectionorderadditional父节点的第一个状态元素? [英] How do I check if first status element from protectionorder parent node equals first status element from mnprotectionorderadditional parent node?

查看:130
本文介绍了如何检查来自protectionorder父节点的第一个状态元素是否等于来自mnprotectionorderadditional父节点的第一个状态元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查具有Op =A或E的ProtectionOrder中的第一个状态是否与具有Op =A或E的MNProtectionOrderAdditional中的第一个状态相同。



如果它们不相等,我会抛出一个系统错误,例如抛出新的System.Exception(状态不同步。详细信息选项卡与附加不匹配选项卡状态。)



如何在VB.Net中使用if语句执行此操作?



在我的Vb.Net代码中,xml文档位于 aobjXmlInputDoc 对象中。所以要获得状态元素我会这样做



用简单的英语我的逻辑看起来像这样

如果是Op的第一个状态=来自ProtectionOrder的A或E<>从MNProtectionOrderAdditional然后返回第一个状态

抛出新的System.Exception(状态不同步。详细信息选项卡与其他选项卡状态不匹配。)

结束如果





这是我的xml文档。

I would like to check if the first status in ProtectionOrder with Op="A" or "E" is the same as first status in MNProtectionOrderAdditional with Op="A" or "E".

If they are not equal, I will throw a system error like this Throw New System.Exception("Statuses out of sync. The detail tab does Not match the additional tab status.")

How do I do this using if statement in VB.Net?

In my Vb.Net code, the xml document is in aobjXmlInputDoc object. So to get Status element I will do it this way

In plain English my logic will look like this
If the first status with Op=A or E from ProtectionOrder <> to first Status from MNProtectionOrderAdditional Then
Throw New System.Exception("Statuses out of sync. The detail tab does Not match the additional tab status.")
End If


Here is my xml document.

<Integration>
	<ProtectionOrder>

		<Statuses>
			<Status Op="A">
				<Current>true</Current>
				<Active>No</Active>
				<Date Op="A">12/13/2018</Date>
				<Type Op="A" Word="EXPIRED">Expired</Type> 
			</Status>
			<Status>
				<Current>false</Current>
				<Active>Yes</Active>
				<Date>12/13/2016</Date>
				<Type Word="SBJO">Signed By Judicial Officer</Type>
			</Status>
			<Status>
				<Current>false</Current>
				<Active>No</Active>
				<Date>12/13/2016</Date>
				<Type Word="DRAFT">Draft</Type>
			</Status>
		</Statuses>

		<MNProtectionOrderAdditional>
			<Statuses>
				<Status Op="A">
					<Current>false</Current>
					<Active>No</Active>
					<Date Op="A">12/13/2018</Date>
					<Type Op="A" Word="EXPIRED">Expired</Type>
				</Status>
				<Status>
					<Current>false</Current>
					<Active>Yes</Active>
					<Date>12/13/2016</Date>
					<Type Word="SBJO">Signed By Judicial Officer</Type>
				</Status>
				<Status>
					<Current>true</Current>
					<Active>No</Active>
					<Date>12/13/2016</Date>
					<Type Word="DRAFT">Draft</Type>
				</Status>
			</Statuses>


		</MNProtectionOrderAdditional>
	</ProtectionOrder>
</Integration>





我尝试了什么:



这是我正在尝试但需要帮助的。





What I have tried:

This is what I am trying but need help with it.

In VB.Net I am not sure how to do it. This is where I need help.

If aobjXmlInputDoc.DocumentElement.SelectSingleNode("Integration/ProtectionOrder/Statuses/Status[1]/@Op") <> aobjXmlInputDoc.DocumentElement.SelectSingleNode ("Integration/ProtectionOrder/MNProtectionOrderAdditional/Statuses/Status[1]/@Op") Then
 Throw New System.Exception("Statuses out of sync.  The detail tab does Not match the additional tab status.")
End If

推荐答案

SelectSingleNode [ ^ ]返回 XmlNode [ ^ ]对象。 XmlNode 类没有实现相等运算符,因此您正在执行引用比较。由于两个节点不是同一个实例,它们彼此不相等,并且您的代码将始终抛出异常。



比较节点'值属性 [ ^ ]。

SelectSingleNode[^] returns an XmlNode[^] object. The XmlNode class does not implement equality operators, so you're performing a reference comparison. Since the two nodes are not the same instance, they are not equal to each other, and your code will always throw the exception.

Compare the nodes' Value property[^] instead.
If aobjXmlInputDoc.DocumentElement.SelectSingleNode("Integration/ProtectionOrder/Statuses/Status[1]/@Op").Value <> aobjXmlInputDoc.DocumentElement.SelectSingleNode ("Integration/ProtectionOrder/MNProtectionOrderAdditional/Statuses/Status[1]/@Op").Value Then


这篇关于如何检查来自protectionorder父节点的第一个状态元素是否等于来自mnprotectionorderadditional父节点的第一个状态元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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