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

Re: Create XML


Re:  Create XML
[Rich Salz]

> I didn't say it was easy.  I said it was disappointing that the average
> programmer can't just output a little bit of XML -- a config file,
> for example -- without some heavyweight API.  That would mean, for
> example, embedded returns -- unnormalized line-end -- are out of
> scope for what I was talking about.
>

Well, for simple files where you __know__ you will not run into the harder
problems - like some of those config files, say, - and especially if you
know there will not be attributes - I like to use a little element generator
that returns a complete element as a string.  That way it is well-formed,
and you can use it recursively.

It could look like this -

result = element('div','This is the content')
result += element('p', element('b','Let us start with bold') + 'this is not
bold')

You use string or RE replace to handle the more obvious escaping and do not
worry about empty element syntax.   Very easy to program, gives you
well-formed output (modulo encoding, but just stick with ASCII or iso-8859-x
if you know your editor will produce it), flexible to use.  Extending it to
attributes is not hard, __if__ you know your input won't come from James
Clark or some other trickster.

It is crude, but I have spooled out a lot of xml from javascript just this
way.  It is better than writing the string fragments, much better.  It is
only good when you __know__ you will not bump up against all the nasties.
Of course, how can a newbie know that??? Oh well...

Cheers,

Tom P



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.