read specific xml values


As usual, my user requirements have changed at the point of delivery...  I have written an app that will push out data to XML and a webpage that will read all the vlaues using this code and a data grid
(snippet ID 8230700)
 but now my user wants to be able to search the XML for specific records from the Stub Value
(snippet ID 8230701)

I am writing in\ 2.0  and would be grateful for any help.

There will be a minimum of two records per stub value and will need to show all records matching that specific stub value.

Any help will be gratefully received.  

Dim ds As New DataSet()
        If File.Exists("\\wintdc02\PUBLIC\TarehouseXML\" & machine.Text & year.Text & month.Text & day.Text & ".xml") Then
            ds.ReadXml("\\wintdc02\PUBLIC\TarehouseXML\" & machine.Text & year.Text & month.Text & day.Text & ".xml")
            datagrid1.DataSource = ds
            Response.Write("The file you are looking for does not exist or has been moved")
        End If

Open in new window

- <sample>
   <SugarValue /> 
   <AminoValue /> 
   <SodiumValue /> 
   <PotasiumValue /> 

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Can you use Linq?
SimonPrice33Author Commented:
I have just moved my project into a .Net 3.5 Framework so should be able to now...  but still not entierly sure on how to do it...
Do you mean that the user wants to be able to search through all existing xml files for a given value of "stub"?

Because that is going to be slow, opening each xml file and search for a given value. Better store everything in a database and search.

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

SimonPrice33Author Commented:
Hy Sybe,

Yes thats what they would like to do...   Speed wont be too much of an issue because they will be pulling the files from a server local to that site and there is a new file for each day so it wont be cycling through thousands upon thousands of records.

The most we will be talking about is 400 records at a worst case scenario. I agree a database would be the better way forward but we are just managing to get them off of a line printer so this is a huge step in the right direction...

käµfm³d 👽Commented:
Using the XML you posted, you could do something like this:

Module Module1

    Sub Main()
        Dim records = From record In XDocument.Load("input.xml") _
                                              .Descendants("sample") _
                      Where record.<Stub>.Value = "99999999A" _
                      Select record

        For Each record In records

    End Sub

End Module

Open in new window

where "records" would be the equivalent to your "ds". You can assign the query directly to the data source also:

datagrid1.DataSource = records

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
you can get the rows of the datatable in the dataset by using select. =)

Dim Rows() As DataRow = ds.tables(0).Select("[Stub]='" & string_SearchValue & "'")

if rows.length >0 then
'xml contains stub value
'xml does not contain stub value
SimonPrice33Author Commented:
This worked a charm, although datagrid1.DataSource = records didnt present how I would have expected it to...

but you have given me enough to work with for now.

Thank you
SimonPrice33Author Commented:

I am currently testing with 3 records with the same stub value but all are returning on the same line in my aspx page.

i have tried system.environment.newline, </br>, vbcr, vbcrlf, chr(13), vbnewline to try and get the new record onto the next line, however none of these work.

Do you have any suggestions?
käµfm³d 👽Commented:
Use <br />, not </br>. Web pages naturally consolidate multiple whitespaces, so newlines don't work (I think they do in a <pre> tag).
käµfm³d 👽Commented:
I should say "browsers" naturally consolidate multiple whitespaces, not web pages.
SimonPrice33Author Commented:
ive got it sorted now thanks, have written the response.write into a table that shows the data how I would like it.

Thank you very much for your help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.