Re: yet another xml generator
- From: "Martin Busik" <martin.busik@xxxxxxxx>
- Date: Wed, 19 Mar 2008 23:37:00 +0100
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
.
- Follow-Ups:
- Re: yet another xml generator
- From: Darin McBride
- Re: yet another xml generator
- From: John Bokma
- Re: yet another xml generator
- References:
- yet another xml generator
- From: Martin Busik
- Re: yet another xml generator
- From: Darin McBride
- yet another xml generator
- Prev by Date: Re: Increase file reading efficiency
- Next by Date: Re: yet another xml generator
- Previous by thread: Re: yet another xml generator
- Next by thread: Re: yet another xml generator
- Index(es):
Relevant Pages
|
|