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 ]

ok, i need to have something in real time, callable as a C library that
works like a printf.

i've looked at gnome xml and it's very good, based on building a
document and then writing it. this is fantastic as you can have an
apparently chaotic process, building a sensible document and then output
good stuff in one go.

for our large database applications i want to output Mbytes of xml in a
stream as i'm processing records. this is a different problem.

all output goes to stdout.

if i start on the premise of ascii encoding (i18n should follow for
those who need it), i can get my immediate needs covered by the
following (all arguments are null terminated strings):

xml_start_document()

puts out an xml header string "<?xml etc". possibly needs some
arguments, but can get away without it for now.

xml_start_tag(tag)

puts out "<tag", checking for character errors. pushes tag context onto
an internal stack.

xml_attribute(attribute, value)

puts out ' attribute="value"' with utf-8 translations, special character
handling, etc as appropriate.

xml_element(format, args)

outputs ">" if still in context of opening tag.

puts out printf style format and args with additional translations as
necessary. 

xml_end_tag()

outputs closing tag for current tag context.

xml_end_document()

outputs any end of document tags, checks that all tags are closed.

possibly need extra functions for namespace declarations.

well, there goes my weekend ;), unless someone knows of something in c
that has this level of simplicity - i think some of java solutions have
it, but i really need c.

rick
ps this is _not_ a spec, just indicative of what i'd like to find.

On Sat, 2003-06-21 at 13:21, Mitch Amiano wrote:
> I'll second that. It is a basic approach but works fairly well, 
> and you have a convenient place to correct bugs that arise from yet
> another unanticipated input. 
> 
> 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. 
> 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.
> 
> 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.
> 
> Regards,
> 
> Mitch
> 
> Thomas B. Passin wrote:
> > [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
> > 
> > 
> > 
> > -----------------------------------------------------------------
> > 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>
> > 
> > 
> 
> 
> 
> -----------------------------------------------------------------
> 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