XmlDocument request


#1

I am having to parse a lot of XML files contained in zip files. It would be handy to have the following methods to create an XML document from an InputStream:

XmlDocument (InputStream const *);

static XmlElement* parse (InputStream const *);

I currently call readString on the InputStream from ZipFile::createStreamForEntry and pass it XmlDocument::parse but I think it could be more efficient without the intermediate step.


#2

Hmm… You can already write

…which isn’t exactly cumbersome, and reads pretty clearly. I suspect that if you find yourself writing that same code multiple times then it’ll be because there’s some other aspect of your code which needs D.R.Y-ing at a higher level rather than because of any missing functionality in the XML class. For example, why not write yourself a function that takes a zip file and a filename and returns the XML from it?


#3

I was more concerned with the performance of the extra memory copies than the extra lines of code. I assume if I have a very large XML file it would more efficient to pull the data directly from the stream rather than the intermediate step of copying into a string, etc. I guess too much time spent in the embedded world where we have to worry about such things.


#4

Well the XML parser always works on the entire file as a string after fully loading it anyway, so adding that method would make no difference to memory usage. XML files are rarely big enough for the memory use to be significant compared to the extra speed that the parser achieves from having everything pre-loaded.