Re: [xml] Problem in Default Namespace handling defined in DTD

On Mon, Feb 25, 2008 at 06:32:53PM +0530, Ashwin wrote:

   Hi ,

   For the xml file attached the corresponding DTD contains the namespace
   declaration  as a default attribute of the element svg. However when I
   parse the xml file using Sax Api's for the second svg element I do not
   get  the  default nspace as part of the start element Ns callback, for
   the  firstvelement  I get nspace attribute....On debugging I found the
   problem  occurred  when  the namespace has been pushed on the stack if
   the name space occurs a second time the namespace attribute counter is
   updated,  maybe  this  is  the  expected  behaviour, if so there is no
   problem,  however if it is not so then the namespace attribute counter
   nbNs  needs  to  be  incremented.  I  am  attaching  the patch for the

I think it's the expected behaviour, you know the namespace exists at that
point it's correctly in scope, it will be attributed properly, but the
of having defaulting from the DTD is to avoid pollution on nodes in the
serialization. Libxml2 ensures that the namespaces are properly issued
in the tree if saved back but prevent from having that on every single
which is really unnecessary. Doing what you suggest would raise an awful
lot of complaints from people because their documents would suddenly
get namespaces declaration added on all elements instead of the root
(or the top element of the subtree where the namespace is in effect).

    Yes, what you say makes sense, I just thought that in case of sax, it
could be left to the user what he wants to do with the namespace
declarations, but finally yes, I suppose it will not make any practical
difference since the namespace scoping is correct.
Also incrementing nbNs without having pushed the associated data on the
stack looks a fairly sure case of data corruption coming up if you
pop up the given elements, i'm 99% sure it's a potential crasher.
  From what I understood the data is already on the stack, the if check
makes sure of that.

if (nsname != defaults->values[4 * i + 2]) {
            if (nsPush(ctxt, NULL,
                       defaults->values[4 * i + 2]) > 0)
 Its just that, like you pointed out, it might not be of much use to have
the namespace associated with each node, so when a particular element which
has a default namespace declaration in the dtd occurs a second time the
namespace information is not required and so there is no need to increment
the nbNs counter. The popping is done using the another counter in the
context, nsNr which is incremented only if you push the node, basically I
thought the second svg element does not need to push the ns on the stack
since it is already there and therefore could refer to it.....But I fail to
see how it could lead to a crash, then again perhaps I do not see well
enough :(.....
Thanks for the clarification!!!!



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]