Solved

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

Posted on 2013-12-17
10
133 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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