OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: [xml-dev] Create XML

[ Lists Home | Date Index | Thread Index ]

Thomas B. Passin wrote:

> [Mitch Amiano]
>>The thing I don't like about it is that you can't hide the regexp
>>calls in element(), or you'll escape significant delimiters.
> Sure you can.  It  depends on how many of the tricky things you want to
> handle.  Some versions of my code even detect the best quote to use for
> attributes (single or double) and escape where necessary.  Of course you can
> just excape all of them quotes in asttribute values, but this way makes the
> result more readable, which is good when debugging or showing the result to
> someone else.  This gets done within the element() call (which may of course
> delegate the work).

(shrug) Maybe I'm missing something. I'll reply below.

>>A related approach is to use a few more functions, say,
>>starttag(), endtag(), attribute() and escapecontent().
>>More verbose, but you can encapsulate the regexp handling.
> But now you do not automatically get a well-formed xml fragment out of any
> one operation.  That is one of my goals.  It is like an atomic transaction -
> all or nothing.  If the fragments are well-formed, the whole thing ends up
> that way.

True. Sometimes my data structures lend themselves to out-of-order construction, and sometimes it is just easier on the eyes to take the risk.

>>The other technique that has proven useful for some situations is
>>to use a magic string as an escape for the real delimiters, building up
>>a block of XML as needed, then applying a (single but complicated)
>>global regexp to replace everything necessary in one fell swoop.
> Yes, I have done the magic string escapes too, although I tend to do it on
> the little bits at a time rather than all at once.  They are really useful
> when you might already have some escaped ampersands in character content.
> That is, you do not want to escape "& a m p; a second time.

....which was my point at the top. If you escape content every time you call element(), and you nest element() calls, don't you have to play some pretty funky tricks to avoid making entity references out of the delimiters and entity references just placed into the content?

> Cheers,
> Tom P
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> The list archives are at http://lists.xml.org/archives/xml-dev/
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS