Link to home
Start Free TrialLog in
Avatar of SimonPrice33
SimonPrice33

asked on

read specific xml values

Hi,

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 asp.net\vb.net 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
            datagrid1.DataBind()
        Else
            Response.Write("The file you are looking for does not exist or has been moved")
        End If

Open in new window

<Samples>
- <sample>
   <StationID>C2</StationID> 
   <Date>31-Oct-11</Date> 
   <Time>10:50</Time> 
   <Stub>99999999A</Stub> 
   <CleanWeight>000</CleanWeight> 
   <TopsWeight>000</TopsWeight> 
   <SugarValue /> 
   <AminoValue /> 
   <SodiumValue /> 
   <PotasiumValue /> 
  </sample>
 </Samples>

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

Can you use Linq?
Avatar of SimonPrice33
SimonPrice33

ASKER

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.

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...

ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start 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
else
'xml does not contain stub value
endif
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
@Kaufmed

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?
Use <br />, not </br>. Web pages naturally consolidate multiple whitespaces, so newlines don't work (I think they do in a <pre> tag).
I should say "browsers" naturally consolidate multiple whitespaces, not web pages.
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