Click here to Skip to main content
15,890,369 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need a code to search a certain text from a set of xmls in a folder saved to my local drive and display the name of the xml file that has the matching text in it !

Kindly, sort it out !
Posted
Comments
Rajeev Jayaram 11-Feb-12 13:21pm    
What have you tried until now?

Hi

You can read the each xml file using loop method, then fetch the file name in another control if the text is available in the xml else you can move to another file until the all files complete.

Try the below code

TextBox1.Text = "Books" & Environment.NewLine & "Books2"
Dim arrFiles() As String = TextBox1.Text.Split(Environment.NewLine)

For Each f As String In arrFiles
Using reader As New Xml.XmlTextReader(String.Format("C:\Temp\{0}.xml", f))
While reader.Read()
'Do Something
End While
End Using
Next
 
Share this answer
 
Please see my overview below:


  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the classes System.Xml.XmlTextWriter and System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx[^], http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].


—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900