At 09:09 AM 02/05/2001 +0000, Joseph Lama wrote:
>For one of the text-fields in the form I noticed that the users are
>sometimes writing in reserved xml characters,"<" and "&" , which results in
>How should I declare such text-fields in my DTD instead of:
> <!ELEMENT text-field (#PCDATA)>
As Paul Kelly said, there's nothing you can do in the DTD; #PCDATA is the
right content model for any text content, even if it contains the reserved
You've got two choices, both involving some kind of processing to occur
between the time the user enters data in the field and the time you load
the entry into your XML data store.
First, as Paul said, you can scan the entry, replacing every occurrence of
& and < with its "entitized" form.
Second, you can simply wrap the entire entry in a CDATA section, without
scanning it at all. The result passed downstream to whatever application is
handling the data will look like this:
<![CDATA[entered data appears here]]>
While this is may be a simpler solution over the short run, it more or less
just delays the inevitable -- you'll need to "entitize" it at some point if
the data will be persisting in XML form.
John E. Simpson | "Is it weird in here, or is it just
http://www.flixml.org | me?" -- Steven Wright
XML Q&A: www.xml.com |