Click here to Skip to main content
15,907,492 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
XML
<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
Posted
Updated 18-Dec-18 5:31am

1 solution

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.
VB.NET
If aobjXmlInputDoc.DocumentElement.SelectSingleNode("Integration/ProtectionOrder/Statuses/Status[1]/@Op").Value <> aobjXmlInputDoc.DocumentElement.SelectSingleNode ("Integration/ProtectionOrder/MNProtectionOrderAdditional/Statuses/Status[1]/@Op").Value Then
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900