[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2013-12-17
10
Medium Priority
?
136 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 64

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 64

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
Independent Software Vendors: 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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 64

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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