[jdom-interest] setText() to replace children?
Szegedi, Attila
szegedi at scriptum.hu
Mon Jul 16 01:25:22 PDT 2001
>
> setText(s) is a convenience method for
> setContent( new ArrayList().add(s) ).
> That's all it's ever been.
>
Just splitting hairs, but ArrayList.add() returns void.
I guess it's rather a convenience for
setContent(Collections.singletonList(s))
> (Validating against a DTD can't catch out-of-bounds data, or
> improperly typed data, or strip/trim whitespace; also, for such simple
> use cases as embedded XHTML, or even child-elements-in-any-order, the
> DTD becomes prohibitively large. XSchema also fails to catch a lot of
> cases. Screw it. DTDs were invented to suit the needs of SGML
> processors, in which a single application must process many different
> types of documents. But XML is not SGML. My apps know what kind of
> documents they're expecting, and deal with them intimately.)
Right. A DTD was mandatory in SGML so it can help resolve ambiguities that
were allowed in SGML.
Consider the following HTML fragment:
<p center>foo<p>bar
With DTD, the processor was able to figure out "center" (note: no quote
marks in fragment) is a possible value of attribute "align", so it
implicitly handled it as if it were align="center". Also, using DTD it could
figure that a <p> element cannot be nested inside another <p> element, so it
assumed an implicit closing </p> before the second opening <p left>. And
there were other issues as well (i.e. no need to use a CDATA section if the
element content was declared CDATA instead of (#PCDATA)).
As XML prohibits all ambiguities I listed above (and many others), it's much
easier to interpret an XML document in absence of a DTD compared to an SGML
document that extensively uses the optional features -- which pretty much
lessens the value of DTD in XML environment.
>
> --
> Alex Chaffee mailto:alex at jguru.com
Attila.
More information about the jdom-interest
mailing list