Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is there a legitimate use case for being able to recursively define entities like that?


Look again. There's no actual recursion going on. It's fairly trivial to identify recursion in DTD entities.


Rather than nitpicking the terminology, can we answer the actual question: is there any legitimate use case for defining an entity in terms of another entity?


Right, that's the root of the problem: feature creep. Common with design-by-committee.

As with any feature, there are possible use cases. Perhaps you want to create a form document and use custom entities that you modify later to fill the document out.

But the amount of times that's useful is not likely to be worth the potential harm of things like billion laughs. Easy to separate that functionality, and have your XML parser do an element data replace with your own custom tokens. Eg node.replace("{name}", customerName);


DTD entities come from SGML, and are still commonly used as an extensibility/modularity mechanism in XML. XML power users (e.g. for documentation) commonly have DTDs that refer to entities that can be replaced to customize the format. IBM's DITA is an example for this. Having only one level of DTD expansion would make that much less powerful. I think that's a legitimate use case, but the resulting system is still a mess IMHO. Like many macro systems it's very hard to understand and debug, and on top of it you have to understand a relatively obscure format that isn't even XML (DTDs).

That being said, like many of the things in XML, DTDs and entities not very useful outside of publishing/markup use cases, and dangerous on top of it (not only for the billion laughs, e.g. including system entities).


I don't see any recursion. Recursion would be an infinite loop and presumably a good parser would catch that.


No. Recursion can terminate and still be called recursion.

(news.yc used to be a Lisp hangout)


If you read the OP carefully, you'll see he's quite aware of the terminology.

There really isn't any recursion in that XML snippet, none of the entities refers to itself, directly or transitively. If there was, the file would be invalid and the error probably caught by the parser before dying from memory exhaustion. There's no way to terminate recursion in XML entities.


Not sure if you could abort an recursion in XML.


it's really the underlying macro system that's recursive - http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.3.2

and that's probably because macros systems typically are recursive since they are otherwise fairly limited, so this is a way to give them sufficient expressive power. so the explanation is probably "tradition" (and likely made more sense in sgml, which was the precursor to html).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: