$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Stefan Seefeld (seefeld_at_[hidden])
Date: 2007-07-11 09:14:04
David Abrahams wrote:
> Okay, this is going to sound very opinionated:
> 
>   I find XML horrible to read, however I find most of the procedural
>   code I've seen for manipulating it even more horrible.
> 
> I would like to see a more declarative syntax for much of this stuff.
> 
>     element_ptr info = root->insert_element(root->begin_children(), "articleinfo");
>     if (title)
>     {
>       info->insert(info->begin_children(), title);
>       info->insert_comment(info->begin_children(), "This title was moved");
>     }
>     element_ptr author = info->append_element("author");
>     element_ptr firstname = author->append_element("firstname");
>     firstname->set_content("Joe");
>     element_ptr surname = author->append_element("surname");
>     surname->set_content("Random");
> 
> could be something like:
> 
>     root.push_front(
>         tag("articleinfo")[
>              title ? (comment("This title was moved"), title) : NULL
>            , tag("author")[
>                  tag("firstname")["Joe"],
>                  tag("surname")["Random"]
>              ]
>         ]
>     )
> 
> You could use Boost.Parameter to do attributes, or use runtime
> attributes like
> 
>        tag("div", attr("class") = "someclass")[
>              ...
>        ]
>                
> You might be familiar with Nevow's STAN, which I had a hand in.  This
> suggestion is reminiscent of that.
Do you think the above syntax would replace the procedural API, or merely
complement it ? While I can see the appeal of such a declarative approach,
I'm not sure how well that fits into a broader picture where users want to
use the same API not only to build a document, but traverse it, remove and
replace elements, etc.
To me, right now, what you propose looks mostly like syntactic sugar, which
can be worked on as a refinement once the basic (and common) API is established.
>> PS: The current scope of the project is described in
>> http://svn.boost.org/trac/boost/browser/sandbox/xml/README
> 
> Another suggestion: use the .rst extension for ReST documents -- Trac
> will preview them formatted via ReST
Sure, will do. I hadn't even thought of the README as a ReST document. :-)
I'll migrate more things to boost conventions as I have time to work on it.
> [Oh, and I suggest you get the tab characters out of your code)
That, too. Thanks,
                Stefan
-- 
      ...ich hab' noch einen Koffer in Berlin...