Results 1 to 3 of 3

Thread: How do I check if tow Status elements are the same

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2013
    Posts
    43

    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>

  2. #2
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,423

    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.
    Along with the sunshine there has to be a little rain sometime.

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    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
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width