|
Boost : |
From: John Moeller (fishcorn_at_[hidden])
Date: 2007-07-12 03:38:27
Oliver.Kowalke_at_[hidden] wrote:
>> root.push_front
>> (
>> tag("Article Info",
>> (title ? (comment("This title was moved"), title) : NULL)
>> (tag("author",
>> (tag("firstname", "Joe"))
>> (tag("surname", "Random"))
>> ))
>> )
>> );
>
> I find it relay hard to read and I'm missing the typesafety. Nothing
> prevents you to put tag("firstname", "Joe") in place of article info
> tag!
I agree that it's harder to read; I like Dave's syntax better. Somehow,
the square brackets do it for me.
> You are forced to validate it at runtime.
Nothing's really new here. You can't validate XML at compile time.
Unless you mean something different.
> Phils suggestion is more typesafe:
No, it's just more verbose, and there's no way to eliminate all the
intermediate variables.
Type is enforced only by the structure of the data and the way that it's
interpreted by the parser/writer. You may as well pick an interface
that just lets you read/write hierarchical data easily, or support an
extension that already deals with interpretation, like schemas.
> articleinfo ai;
> {
> if (title) ai.push_back(comment("This title was moved"));
> author a;
> {
> a.push_back(firstname("Joe"));
> a.push_back(surname("Random"));
> ai.push_back(a);
> }
> root.push_back(ai);
> }
I don't really see how it's more type-safe. The structures
"articleinfo", "firstname" and "surname" would all inherit from
"element", which is presumably a type accepted by "push_back". So
nothing prevents you from doing:
root.push_back(firstname("Joe"));
which is exactly what you had hoped to avoid.
If you really want type-safety at this level, you'd have to define a
push_back for all the sub-element types accepted by an element (and
push_front, insert, etc.). No thanks.
> I would like to see translating xsd (xml schemas) to c++ classes
> (but this could be a further improvment).
I'd like to see schema support as well.
One other thing that I'd like to see is an XPath library that lets me
traverse *any* hierarchical structure, not just XML trees. That would
have been remarkably handy in a project I worked on a couple years ago.
-- John Moeller fishcorn_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk