Finding multiple XML files for a string

I have a folder with 400k + XML documents and much more, each file has the name 'ID'.xml, and each of them belongs to a specific user. In the SQL server database, I have an "ID" from the XML file associated with the user ID, where I connect the XML document to the user. A user can have an infinite number of attached XML documents (but let a maximum of> 10 thousand documents)

All XML documents have several common elements, but the structure may vary slightly.

Now, each user will have to search the XML documents belonging to her, and what I have tried so far (looping through each file and reading it using streamreader) is too slow. I don't care if it reads and matches the whole file with attributes, etc. Or just text in each element. First of all, you should return the list with the identifier from the file names.

What are the fastest and smartest methods here, if any?

+3
source share
7 answers

I think LINQ-to-XML is probably the direction you want to go.

Assuming you know the tag names that you want, you can search for those specific elements and return values.

var xDoc = XDocument.Load("yourFile.xml");

var result = from dec in xDoc.Descendants()
             where dec.Name == "tagName"
             select dec.Value;

results IEnumerable XML, , "tagName"

:

var result = from dec in xDoc.Decendants("tagName")
             select dec.Value;

:

var result = xDoc.Descendants("tagName").Select(tag => tag.Value);

, .

+2

, , , , , . , .

Xml, , XmlReader, , ( Xml , ). , , .

, -, , , , . , .

" " ? ?

+2

LINQ to XML.

. msdn.

XDocument doc = XDocument.Load("C:\file.xml");

, , ...

+1

, XML , , linq xml - . XML , () ( XML-). xml, ?

: ID, tagName1, tagName2 xmlDocID, value1, value2

: XML- . SQL Server 2005/2008, , xml ( xml)

+1

, ?

. .NET-. , .:)

, , - - grep, . "-l", , , . ( . )

0

L.B . , Lucene.Net( ) . ( ) . - .

- , Lucene?

0

Lucene.NET( Lucene) . , - .

0

All Articles