|
Boost : |
From: Jake Voytko (jakevoytko_at_[hidden])
Date: 2007-07-13 09:31:39
My concern, as I indicated in the other thread, is that
1)
<?xml version="1.0"?>
<article_info isbn="foo">
<title>bar</title>
<author>Testy McTest</author>
</article_info>
2)
<?xml version="1.0"?>
<article_info isbn="foo">
<!--Title goes here-->
<title>bar</title>
<author>Testy McTest</author>
</article_info>
and 3)
<?xml <!-- Prolog tag--> version="1.0"?>
<article_info isbn="foo">
<!-- Author goes here -->
<author>Testy McTest</author>
<!-- Title goes here -->
<title>bar</title>
<!-- Maybe we could add more later-->
</article_info>
are all valid XML documents, and represent the same data. If this library
were solely to be used for writing, I would say that this is not an issue.
However, what is written must be read.
The thing I don't understand about the type-safety proposals is how they
intend to take into account data that is read from a file. Suppose we write
a program to neatly display XML data from any generic XML file:
boost::xml my_doc_reader(filename);
would certainly be a step, and I would expect it to contain a full XML tree
after this step is said and done with no extra intervention. The XML library
certainly can't instantiate the proper structs in memory if we don't know
what they are. Do they exist solely for writing the document?
To me, type safety is a more specific problem than what the XML standard
deals with. Yet, it is a common enough problem to warrant a library
solution.
Perhaps:
public typesafe_xml: public xml
{
};
that requires you to define the document structure in class format, and can
throw runtime exceptions when a document is read in with the wrong format?
Jake
On 7/13/07, Oliver.Kowalke_at_[hidden] <Oliver.Kowalke_at_[hidden]> wrote:
>
> > > I would do it over templates - than it's type safe and a
> > part of the
> > > xml validation can be done at compile time.
> > >
> > > typedef tag<
> > > mpl::vector< title, author > // tags
> > > mpl::vector< isbn > // atributes
> > > > article_info;
> >
> >
> > I hadn't considered compile-time type safety when I wrote my
> > above example.
> > However, I feel an example like this might also preclude XML
> > features like comments. If we were to parse an existing article:
> >
> > <article_info isbn="foo">
> > <!--Article information goes here-->
> > <title>bar</title>
> > <author>Testy McTest</author>
> > </article_info>
> >
> > your definition doesn't immediately make it clear that the
> > comment, when parsed, ends up in the document tree. I may,
> > however, just be missing something. Complicating matters,
> > according to the standard, they can also appear within the
> > document type declaration, so comments significantly
> > complicate the matter:
> > http://www.w3.org/TR/REC-xml/#sec-prolog-dtd
> >
> > And the standard also lists retrieval of comment text as optional:
> > http://www.w3.org/TR/REC-xml/#sec-comments
> >
> > But I think that a Boost.XML library should support the
> > retrieval of the text of comments.
>
> I believe that comments could be supported with a typesafe
> implementation.
> I don't know where you see problems with comments - article_info could
> contain optional instances of comment-class.
>
> Oliver
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk