Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.IO;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication13
{
class Program
{
const string INPUT = @"C:\Users\awise\Downloads\uniprot_sprot.xml";
const string OUTPUT = @"C:\temp\uniprot";
static readonly XNamespace NS = @"http://uniprot.org/uniprot";
static void Main(string[] args)
{
int i = 0;
using (var fs = new FileStream(INPUT, FileMode.Open, FileAccess.Read))
{
using (var reader = XmlReader.Create(fs))
{
while (reader.ReadToFollowing("entry"))
{
var doc = XDocument.Load(reader.ReadSubtree());
string name = doc.Root.Element(NS + "name").Value;
string outputDir = Path.Combine(OUTPUT, name.Substring(0, 1));
if (!Directory.Exists(outputDir))
Directory.CreateDirectory(outputDir);
using (var wr = XmlWriter.Create(Path.Combine(outputDir, name + ".xml")))
{
doc.WriteTo(wr);
}
if (i++ % 1000 == 0)
System.Console.WriteLine(i);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.