Re: [gdome] Namespace - Saving to a File
- From: Chetan Raj <hichetu gmail com>
- To: Paolo Casarini <paolo casarini org>
- Cc: gdome gnome org, veillard redhat com
- Subject: Re: [gdome] Namespace - Saving to a File
- Date: Tue, 3 May 2005 11:15:09 +0530
Hi Paolo,
Thanks a lot for clarifing my earlier doubts and questions.
I still have the following doubts....
>> libxml2 is correct. The namespace associated to a node is a different
>> thing from the namespace declared through the attribute xmlns on a
>> node.
>> The namespace you specify on the createDocument is the namespace
>> associated to the document element node, not the namespace declared on
>> it.
When I
associate a namespace to a document element, wouldn't that mean that
the document element and all its children are under the scope of the
associated namespace. In that sense, doesn't the associated namespace
become the default namespace for the element? Otherwise what does the
association imply?
If the
association implies the default namespace, then wouldn't it be better
for createDocument to put the special xmlns attribute, while its
creating the document element?
Thanks,
Chetan Raj
On 5/2/05, Paolo Casarini <paolo casarini org> wrote:
Hi Chetan,
On Thursday, April 28, 2005, 6:48:44 PM, Chetan Raj wrote:
> When I create a document with a namespace and then save the
> document to a file, then the namespace was not saved.
> Ex: [...]
> For the above code, the test.xml saved was this...
> <?xml version="1.0"?>
> <nm:chet/>
The code you wrote and the resulting xml file are correct wrt to the
current gdome implementation of gdome_di_createDocument.
> When I debugged, I found that libxml xmlNode has two xmlns pointers
> xmlNs*ns; /* pointer to theassociated namespace */
> xmlNs*nsDef; /* namespace definitions on this node */
> InxmlNewNode function, we were poulating only ns and not nsDef.
> (file tree.c line n.o: 2139 ver: libxml2-2.6.11 )
cur->>ns = ns;
> and inxmlNodeDumpOutputInternal function we were checking for
> nsDef to savethe namespace data!! ( file xmlsave.c, line
n.o 743
> ver:libxml2-2.6.11 )
if (cur->>nsDef)
> xmlNsListDumpOutput(buf, cur->nsDef);
libxml2 is correct. The namespace associated to a node is a different
thing from the namespace declared through the attribute xmlns on a
node.
The namespace you specify on the createDocument is the namespace
associated to the document element node, not the namespace declared on
it.
For example you can have a node with two different namespace
declarations but only one namespace associated with it:
<?xml version="1.0"?>
<pers:person xmlns:pers="http://sernaferna.com/pers"
xmlns:html="http.//www.w3.org/1999/xhtml/">
...
</pers:person>
> When I modified tree.c in xmlNewNode function as shown
cur->>ns = ns;
cur->>nsDef = ns; // Added this line to make namespace save to
cur->>file work. Before this Namespaces were not saving to a file.
> Then we were successfully able to save the Namespaces to the file. and the output we got is
> <?xml version="1.0"?>
> <nm:chet xmlns:nm="
http://www.w3.org/2000/svg"/>
> Is the fix I gave correct? Why do we have two xmlNs(ns and nsDef) pointers?
The fix is not correct because the two pointers refer correctly to two
different things.
> If you have any other suggesions to use and save namespaces, please reply to me.
Using your example above you have to get the document element and add
to it the namespace declaration that you want to declare on that
element node:
...
GdomeElement* el = gdome_doc_documentElement(doc, &exc);
GdomeDOMString* attr_name = gdome_str_mkref("xmlns:nm");
gdome_el_setAttributeNS(el, attr_name, ns, &exc)
...
Bye,
Paolo.
--
GPG key: 1024D/9C5AE886 2004-10-21 Paolo Casarini <paolo casarini org>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]