Default attribute values
- From: xmlpp otpproductions com
- To: libxmlplusplus-list gnome org
- Subject: Default attribute values
- Date: Mon, 27 May 2013 21:38:48 -0700
Hi all --
I'm porting a python server to C++. I auditioned a lot of XML
frameworks, and for me libxml++ was hands down the most usable. It
lets me think like a C++ programmer instead of like a standards
author. So thanks for that!
However, we have been relying on default values of attributes defined
in a DTD. We've written a lot of python client programs that send XML
to the server, and they don't specify all the attributes. The python
XML framework we used (amara) would add them in when it validated.
That is not happening when I use libxml++. I take the XML sent in to
the server by a client, and combine it in memory with a DTD the server
knows about. I construct a DOMParser and call set_validate() on it,
and then call DOMParser.parse_memory(). It does correctly flag
invalid XML, but it does not add in attributes with default values.
I don't know anything about libxml2, but I've read a lot of source
tonight. It appears to me that DOMParser::parse_memory() calls the C
function xmlCreateParserMemoryCtxt(), which creates some in-memory
data structures but does not set any options. Then the C++
DomParser::parse_context() is called. This calls the C++ function
Parser::initialize_context; if set_validate() has been called
previously then initialize_context() adds the XML_PARSE_DTDVALID
option to the context. After initialize_context() returns,
parse_context() calls the C function xmlParseDocument().
I know libxml2 can insert default parameters, because if I call the
xmllint program (part of the libxml2 distribution) with the command
line options '--valid --dtdattrs', the output has the default
attributes inserted. From reading the source for xmllint, it appears
the key step is EITHER setting the XML_PARSE_DTDATTR option on the
parser before calling the parse function; OR setting the
XML_COMPLETE_ATTRS bit in the global C variable
xmlLoadExtDtdDefaultValue before calling the parse function. I didn't
see any way to do either of those as a user of libxml++.
Have I missed something? Is there acurrently a way to get this
behavior?
If not, should I file a bug? It seems to me that this should be the
default behavior -- if a DTD writer goes to the trouble of adding
attributes with default values, they want the parser to implement
them. Of course, doing that in libxml++ would be a
non-backward-compatible change; although I think it would be a fairly
benign change -- for most programs the appearance of additional
attributes won't have any effect. But probably that's a bad idea; how
about adding a set_dtdattrs() function to the Parser class, which one
could call before calling Parser::parse_* function?
Thanks for your attention!
Bob Nolty
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]