Question

From "parsing speed" point of view, how much influence(if any) has number of attributes and depth of XML document on parsing speed? Is it better to use more elements or as many attributes as possible? Is "deep" XML structure hard to read?

I am aware that if I would use more attributes, XML would be not so heavy and that adapting XML to parser is not right way to create XML file

thanks

Was it helpful?

Solution

I think, it depends on whether you are doing validation or not. If you are validating against a large and complex schema, then proportionately more time is likely to be spent doing the validation ... than for a simple schema.

For non-validating parsers, the complexity of the schema probably doesn't matter much. The performance will be dominated by the size of the XML.

And of course performance also depends the kind of parser you are using. A DOM parser will generally be slower because you have to build a complete in-memory representation before you start. With a SAX parser, you can just cherry-pick the parts you need.


Note however that my answer is based on intuition. I'm not aware of anyone having tried to measure the effects of XML complexity on performance in a scientific fashion. For a start, it is difficult to actually characterize XML complexity. And people are generally more interested in comparing parsers for a given sample XML than in teasing out whether input complexity is a factor.

OTHER TIPS

Performance is a property of an implementation. Different parsers are different. Don't try to get theoretical answers about performance, just measure it.

Is it better to use more elements or as many attributes as possible?

What has that got to do with performance of parsing? I find it very hard to believe that any difference in performance will justify distorting your XML design. On the contrary, using a distorted XML design in the belief that it will improve parsing speed will almost certainly end up giving you large extra costs in the applications that generate and consume the XML.

If you are using Sax parser it does not matter whether XML is a large one or not as it is a top down parser and not hold the full XML at memory but For DOM it matters as it holds the full XML in memory. You can get some idea about comparison of XML parsers in my blogpost here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top