Working with XML files is generaly a pleassure :-) Because of the nature of XML beeing verry intiuative, structures, and capable of reflecting almost evetything. BUT: Have you eaver worked on a document that was so big that it was imposibil to find the items that you want? Well i have... Personaly i have made lots of programs where setup information was done in xml, data files was done in xml, and so on and so on... Often thease files start out containing 20-50 lines of tags, and each time you write som extra code you just add 5-10 lines of setup. So instead of making databases and complex data management systems you often just add more and more xml to the same file. Ending up with a 500+ lines xml file.
This is kind of anoing when you edit them. So instead what i wanted was to doo XML includes :-) Split the xml files in multriple files, and just include sections here and there... So that i end up with maby 20-50 smaler files containing sections of the data, and a single 20-50 lines master file that bind it all together ;-) That's a nice approach ...
This problem that i kepet running into was: Theres no common standart for xml includes. Yes there are standards, but verry few parsers acturaly implement the stardarts :-( So getting the includes to work at all require tones of work. And the reason for using includes is to save me from dooing work! Not add to the work load...
So what to doo?
The way i fixed the problem was to create a small program (Download below) that can build a complete xml files from smaler files. It's verry simple and basic but it works! What you doo is you create a "Master File" that contains the root element, layout, etc. And a set of files containing the "Data"... Then in the Main file you write a single include line to include the content from another file.
I have these 5 files: [Setup.XML], [Master.XML], [Persons.XML], [Company.XML], [CompanyDescription.XML].
The master.xml file looks like this.
<?xml version="1.0" encoding="utf-8"?> <root> #include"Persons.xml" #include"Company.xml" </root>
The Persons.xml looks like this.
<Person> <Name>Anders</Name> <City>New York</City> </Person>
The Company.xml looks like this.
<Company> <Name>MyCompany</Name> <WorkingArea>Software</WorkingArea> <Description> #include"CompanyDescription.txt" </Description> </Company>
The CompanyDescription.txt may look like this.
MyCompany is a small busness that make software.
Then to bind it all together i have a setup file eg. called setup.xml that describes what to doo.
<?xml version="1.0" encoding="utf-8"?> <Setup> <InFile>Master.xml</InFile> <OutFile>DataFile.xml</OutFile> </Setup>
What the program then does is look for the include keyword and exchange that with the data that is in the reffered file instead. Verry semple but effective. So the example above will take the setup.xml as an input (Eighter from a command line, or adding it from the gui) and that wil then generate a complete xml ready to use in any parser :-)
The example DataFile.xml would look lige this after the generation has run.
<?xml version="1.0" encoding="utf-8"?> <root> <Person> <Name>Anders</Name> <City>New York</City> </Person> <Company> <Name>MyCompany</Name> <WorkingArea>Software</WorkingArea> <Description> MyCompany is a small busness that make software. </Description> </Company> </root>
That should be something any xml parser can read! Dooing the split on files as small in the example is kind of pointless because almost anyone can hanle that small files. But imagine that the marketing person in "mycompany" don't know xml, then it will be nice that he can change the description without risking to destroy the hole xml structure. Or imagine you data file has 200 persons, and 60 company's ... Then you realy get a great benifit from splitting the data in seperate files :-)
The program is protected by Copyrights, but may be downloaded free of charge for non-commercial usage.
The complete program and source code in C# and can be downloaded here.
For full commercial usage pay 10$ USD, and save the receipt.
To run i require .Net 2.0 that (If it's not already on your machine) can be downloaded from microsoft.
Xp SP3, Win7, Win8 should not need this...