Click here to Skip to main content
15,907,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using the following xml document, I need help in vb.net. I would like to set a variable (InCustody) to have value = 5 when /[JuvenileCitationDocument or CitationDocument]/Citation/Citee/InCustodyIndicator = True
How do I do this?
I am considering putting the xml document into an object e.g. objXMLInputDoc. This document (CitationDocumentBatch) will have or can have many CitationDocuments and or JuvenileCitationDocuments.
I will then look into this document for each CitationDocument and or JuvenileCitationDocument.
When I find InCustodyIndicator = true (a child element) of a CitationDocument or JuvenileCitationDocument then I want to set a variable to have 5 as it's value.
I will use this value later on.

XML
<CitationDocumentBatch>
	<CitationDocument>
		<Incident>
			<Citee>
				<InCustodyIndicator>true</InCustodyIndicator>
			</Citee>
		</Citation>
		</CitationDocument
	<CitationDocumentBatch>
	<JuvenileCitationDocument >
		<Incident>
			<Citee>
				<InCustodyIndicator>true</InCustodyIndicator>
			</Citee>
		</Citation>
	</JuvenileCitationDocument
</CitationDocumentBatch>


What I have tried:

I am considering putting the xml document into an object e.g. objXMLInputDoc. This document (CitationDocumentBatch) will have or can have many CitationDocuments and or JuvenileCitationDocuments.
I will then look into this document for each CitationDocument and or JuvenileCitationDocument.
When I find InCustodyIndicator = true (a child element) of a CitationDocument or JuvenileCitationDocument then I want to set a variable to have 5 as it's value.
I will use this value later on.
Posted
Updated 10-Aug-18 10:33am

1 solution

Once you create "classes" for your XML (see VS XML paste special), you can use a LINQ query:
C#
CitationDocumentBatch batch = ...;

bool inCustody = 
   batch.CitationDocument.Any( cd => cd.Incident.Citee.InCustodyIndicator ) ||
   batch.JuvenileCitationDocument.Any( jd => jd.Incident.Citee.InCustodyIndicator );

If ( inCustody ) { // etc. }
 
Share this answer
 
v2

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