Re: yet another xml generator



Hi Darin,

This looks really interesting. What would hold me back, personally, is
integrating it into other methods. For example, I usually have a stock, or
template, XML file, and then use XML::Twig to read that, add/remove/modify
what I need to, and write it out (to a file, to stdout for apache to send,
whatever). If I could do something like:
$twig->insert_decl('after',
twig_element "out", content {
#...
});

I'm haven't used XML::Twig before, what is the meaning of insert_decl('after',xxx) ?
May be, you can give me an another example?

[element vs. opt_element]
I would suggest that $value as undef should do this, if it's "", then it
should insert the empty element. In fact, I'd merge your element and
opt_element together:
element "abc"; #creates the "abc" element, empty
element "abc", ""; # same thing
element "abc", undef; # no-op

I have cases in my projects, where xml schema specifies that there must me an
element, independent of its contents. If I'd select a null from a database,
I had to convert it to "", if the appropriate element is mandatory.
Therefore I like to keep the two cases distinct.

Another example may show the benefit when there are more hierarchy levels:

opt_element "contact-data", content {
opt_element "email", $email;
opt_element "phone", $phone;
opt_element "fax", $fax;
opt_element "postal-address", content {
opt_element "street", $street;
opt_element "city", $city;
opt_element "zip-code", $zip;
}
}

if all of the above variables contain either undef or "", no output is generated
at all. IMO this makes it more readable.


Also, how do I put an element in the middle of the text of another element?
Does this work?
element "p", "a paragraph with some ", element("b", "bold"), " text";
I'm guessing not. If my guess is correct, I'd suggest at least adding that
as a limitation in the POD.

Your point is good. It is possible, but there is a syntacticall difference:
(I haven't mentioned the "text" function):

element "p", content {
text "a paragraph with some ";
element "b", "bold";
text " text";
}

element "name", "scalar-value" is expanded to element "name", text "scalar-value"

Do you have any idea for naming a package with that functionality?

Cheers,
Martin

.



Relevant Pages

  • What Not to Do (a cautionary tale)
    ... script that reads in an XML file and an ERB template, ... to the template, and writes out the result to a file. ... and all hell broke loose as a result. ... Don't upgrade your Ruby environment unless you need to ...
    (comp.lang.ruby)
  • plugin architecture - repost
    ... I am building an application to help researcher record the outcomes of their ... These outcomes are document across a number of paper forms. ... I've created a number of these 'template' files. ... to use a specific template, I open the XML file, deserialize it, add data to ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Word 200 Macro using replace
    ... this field is populated from different fields in an XML file. ... The carraige ... returns aren't part of the template, they come from the XML file". ... > create a macro that will run automatically everytime a new .doc file is ...
    (microsoft.public.word.docmanagement)
  • "value substitution/population" in template XML using XPath
    ... I need to populate a large number of "template" XML files ... indicated in a seperate XML data file as, ... another XML file. ...
    (comp.text.xml)
  • Re: automating email with links to records just submitted to an SQL DB using asp.net (vb)
    ... What I usually do for emailing is create an XML file and call it, say, ... public static void Send(string templatePath, string templateID, string ... recipients, Hashtable tokens) ... XmlDocument template = new XmlDocument; ...
    (microsoft.public.dotnet.framework.aspnet)