On Tue, Sep 07, 2010 at 04:35:54PM -0400, Patrick McClory wrote: > Hello, > > I'm working on a project which requires validation of xml documents against > .xsd schemas. We both create xml documents from scratch, and create xml docs > from char * buffers read from a socket. I've run into trouble validating the > docs created from buffers, even when the buffers are generated from a > document that already validated successfully.
> //set the namespace > root_node->ns = xmlNewNs(root_node, BAD_CAST > "http://localhost/test_namespace", NULL); > root_node->nsDef = root_node->ns; From a tree perspective the root has a namespace, which is defined as a default namespace > //create the children > xmlNsPtr child_ns = xmlNewNs(NULL, NULL, NULL); have you checked what this returns ? What is that supposed to mean ? > xmlNewChild(root_node, child_ns, BAD_CAST "element1", BAD_CAST "foo"); > xmlNewChild(root_node, child_ns, BAD_CAST "element2", BAD_CAST "1"); while the children have a namespace which is basically not defined. > xmlSaveFormatFileEnc("generated.xml", doc, "UTF-8", 1); > I dump both docs to output files (generated.xml and buffer.xml), and I > confirmed that they're the same on disk using diff. when you serialize, I bet the child_ns does not appear. > The problem seems to be that when libxml reads from the buffer it attaches > the parent namespace to the children (if it isn't specified), which later > causes validation to fail. Is this a common problem? Is there a standard > workaround for this? The problem is that basically you defined the root namespace as a default namespace (no prefix), that the broken namespace used for the children is not serialized and as a result the output document have the children inheriting the default namespace from root. Don't use a default namespace on the root. and fix the children namespace definition. Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ [email protected] | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ _______________________________________________ xml mailing list, project page http://xmlsoft.org/ [email protected] http://mail.gnome.org/mailman/listinfo/xml
