Solved

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

Posted on 2013-12-17
10
134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 63

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 63

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 63

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 63

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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