How do I check if tow Status elements are the same
I would like to check if the first status element in ProtectionOrder with Op="A" or "E" is the same as first Status element 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
In VB.Net I am not sure how to do it. This is where I need help.
Code:
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
Here is my xml document.
Code:
<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>
Re: How do I check if tow Status elements are the same
No answers to this yet !
Sorry, this forum is usually far better than that.
Maybe the question sounds much more complicated than it is ?
The simple and straightforward answer would be to use the 'not equal to' method.
e.g.
Code:
If A <> B Then
'Do this.
End If
Poppa.
Re: How do I check if tow Status elements are the same
Try using XElement and LINQ. This code uses your example XML
Code:
Dim xe As XElement
' xe = XElement.Load("path to file or URI")
'for testing use literal
xe = <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>
Dim ProtectionOrderOPaORe As IEnumerable(Of XElement)
ProtectionOrderOPaORe = From el In xe.<ProtectionOrder>.<Statuses>...<Status>
Where el.@Op = "A" OrElse el.@Op = "E"
Select el Take 1
If ProtectionOrderOPaORe.Count = 1 Then
Dim AddProtectionOrderOPaORe As IEnumerable(Of XElement)
AddProtectionOrderOPaORe = From el In xe.<ProtectionOrder>.<MNProtectionOrderAdditional>.<Statuses>...<Status>
Where el.@Op = "A" OrElse el.@Op = "E"
Select el Take 1
If AddProtectionOrderOPaORe.Count = 1 Then
'checks here to see if the firsts meet req.
' e.g.
If ProtectionOrderOPaORe(0).@Op <> AddProtectionOrderOPaORe(0).@Op Then
Stop
End If
End If
End If