Such questions are hard to answer ;-)
The second variant allows you more flexibility if ever you should feel the need to add more details to the "freq".
The first is simpler, on the other hand. I'd go with the first one (attribute) here.
And, yes, generating xml in that way is perfectly ok - esp. for such trivial structures.
If you had some generic tree structure, you could of course write a generic "toXml" traversal function... but since you have nothing of the kind, you would save no work if you were to generate some intermediate structure first.
Maybe, if your attributes get more numerous, you might want to introduce some helper class (I am sure there exists something like that in the Java universe), and create a tag; call some addAttribute() methods and finally print that tag (maybe with a passed indentation or so).
Don't overdo it, though. Otherwise you end up coding a xml DOM. (And if you want to use one, just grab one of the existing ones.)
HTH




Reply With Quote
Bookmarks