Solved

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

Posted on 2013-12-17
10
127 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now