[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Create XML


xml escapes
Thomas B. Passin wrote:

> [Mitch Amiano]
snip
>>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>
> 
> 



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.