Solved

Help with filtering data from source with data separated by ",".

Posted on 2013-12-17
10
130 Views
Last Modified: 2013-12-18
Hello,

My xml file contains a country element with multiple countries, for example

<Country>BEL,CAN,DEU</Country>

When I select a cuntry from a control and retreive BEL.

How do I find all the country elements wich contain BEL?

Thanks,

Victor
0
Comment
Question by:vcharles
  • 6
  • 4
10 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39725083
Hi Victor;

Well if you were using Linq to XML you would filter on the Country node and see if the inner text of that node contains the substring BEL for example.
0
 

Author Comment

by:vcharles
ID: 39725098
Can you please send me an example. Thanks.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39725117
That is possible but please attach a sample of the xml file so I can create a sample.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:vcharles
ID: 39725426
Hi,

Below is an example of the xml file. <?xml version="1.0" standalone="yes"?>
<Root>
  <Row>
    <Donor_ID>1</Donor_ID>
    <Donor>BEL,CAN,DEU</Donor>
  </Row>
  <Row>
    <Donor_ID>2</Donor_ID>
    <Donor>CAN,CZE</Donor>
  </Row>
  <Row>
    <Donor_ID>3</Donor_ID>
    <Donor>CZE,USA</Donor>
  </Row>
  <Row>
    <Donor_ID>4</Donor_ID>
    <Donor>DNK,CAN,FRA</Donor>
  </Row>
  <Row>
    <Donor_ID>5</Donor_ID>
    <Donor>FRA,BEL</Donor>
  </Row>

IF I select BEL from a control, my grid should display the following two rows.:

BEL,CAN,DEU
FRA,BEL

Thanks

V.
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39725503
Hi Victor;

Try this code out. It should give you what you need.

' The location of the XML file to be parsed
Dim xdoc = XDocument.Load("C:\Working Directory\test.xml")
Dim findStr As String = "BEL"

' Locate all the Donor nodes and see if it has the value we are looking for.
Dim result = (From d In xdoc.Descendants("Donor")
              Where d.Value.Contains(findStr)
              Select d.Value).ToList()

' Output the results in the List
For Each s As String In result
    Console.WriteLine( s )
Next

Open in new window

0
 

Author Comment

by:vcharles
ID: 39725568
I will try it and get back to you.

Thank You.
0
 

Author Comment

by:vcharles
ID: 39725649
It works!

Thanks. How do I pass the values of S to a DataGridView?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39725739
Hi Victor;

That all depends on if the DataGridView already exist or not. If it does exist does the column exist you want to fill exist or not. There is much more information needed to be able to answer that question.

Also please note that there is only one question allowed per thread and any number of followup questions  to the original question.
0
 

Author Comment

by:vcharles
ID: 39726267
Hi,

Ok, I will open another thread.

Thanks
0
 

Author Closing Comment

by:vcharles
ID: 39726374
Thank You!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question