Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Please stare at this structure for a second :)

enter image description here

I should create such a thing all at run time. What are the values that we pass in at run time? the string values you see after "#" are passed in so for example AnimalBio, ClinBio, HumanGenome,etc... So I am thinking of declaring some methods like

void AddDeclaration(string str) ;
void AddSubClass(string parent, string child);

such that when I call them they will create those XML-ish tags for me with the values I pass in such as HumnaBio.

These are around 15000 items that I am gonna add... What is the best approach that you would suggest for doing this? Do you think using XMLDocument class is the best way of doing it? or do you think I should go with StringBuilder class and add these as strings, or other ways of doing it?


share|improve this question
I don't understand. Why do you want to create XML files at runtime? – Jim G. Aug 7 '12 at 23:23
@JimG. well I need to! Just like when we create files at run time..actually even can think of it as a file..because I finally will save it with ".owl" extension... – Blake Aug 8 '12 at 1:23
Yes - Why do you need to create files at runtime? – Jim G. Aug 8 '12 at 1:25
@JimG. -- There are 10000 decent reasons to generate xml files at runtime. You might want to save some data for your program to use. You might want to save some data for another program to use. You could just love XML. Not sure why it is odd to you. – Wyatt Barnett Aug 9 '12 at 11:57
up vote 4 down vote accepted

In .NET, your best bet would be to take advantage of built-in XML serialization. This would let your class look and behave like a class and magically generate (and read from) your XML.

If I couldn't get this to go -- which can be a challenge depending on how the XML is specc'd -- you have a few options. One would be a completely custom Xml serialization using IXmlSerializable. Another is just a roll your own approach using XmlDocument or XmlTextWriter or many other Xml oriented classes in .NET. This approach should be generally avoided.

share|improve this answer

I think I would just write a simple document template processor that would take exactly the same XML you posted and go through and replace every "#"-denoted placeholder with a value you specify. I think going through a resource-heavy XML object is overkill for what you're doing. I don't know if there's a .NET equivalent to Velocity, but that's the direction I'd take.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.