/usr/share/doc/libxml2-devel
NameSizeModeActions
examples/-0755rm
html/-0755rm
tutorial/-0755rm
APIchunk0.html301330644editdlrm
APIchunk1.html373650644editdlrm
APIchunk2.html407660644editdlrm
APIchunk3.html361100644editdlrm
APIchunk4.html362040644editdlrm
APIchunk5.html297640644editdlrm
APIchunk6.html292120644editdlrm
APIchunk7.html328560644editdlrm
APIchunk8.html302970644editdlrm
APIchunk9.html287000644editdlrm
APIchunk10.html642300644editdlrm
APIchunk11.html326500644editdlrm
APIchunk12.html876010644editdlrm
APIchunk13.html618210644editdlrm
APIchunk14.html455890644editdlrm
APIchunk15.html442810644editdlrm
APIchunk16.html362940644editdlrm
APIchunk17.html483950644editdlrm
APIchunk18.html429430644editdlrm
APIchunk19.html365700644editdlrm
APIchunk20.html328200644editdlrm
APIchunk21.html375730644editdlrm
APIchunk22.html576480644editdlrm
APIchunk23.html638550644editdlrm
APIchunk24.html940330644editdlrm
APIchunk25.html412310644editdlrm
APIchunk26.html308280644editdlrm
APIchunk27.html337810644editdlrm
APIchunk28.html582400644editdlrm
APIchunk29.html134850644editdlrm
APIconstructors.html595020644editdlrm
APIfiles.html3288580644editdlrm
APIfunctions.html2172420644editdlrm
APIsymbols.html3260980644editdlrm
architecture.html68650644editdlrm
bugs.html102350644editdlrm
catalog.gif61050644editdlrm
catalog.html236480644editdlrm
contribs.html76800644editdlrm
docs.html76270644editdlrm
DOM.gif31660644editdlrm
DOM.html66190644editdlrm
downloads.html82900644editdlrm
encoding.html194160644editdlrm
entities.html94450644editdlrm
example.html131070644editdlrm
FAQ.html211380644editdlrm
guidelines.html176610644editdlrm
help.html63150644editdlrm
index.html106710644editdlrm
interface.html82130644editdlrm
intro.html72090644editdlrm
library.html149970644editdlrm
libxml.gif76920644editdlrm
libxml2-api.xml.gz1619110644editdlrm
Libxml2-Logo-90x34.gif30700644editdlrm
Libxml2-Logo-180x168.gif81950644editdlrm
namespaces.html83390644editdlrm
news.html2037840644editdlrm
python.html199060644editdlrm
redhat.gif6970644editdlrm
searches.html75590644editdlrm
smallfootonly.gif27720644editdlrm
structure.gif55590644editdlrm
threads.html71150644editdlrm
tree.html79130644editdlrm
upgrade.html126670644editdlrm
w3c.png20280644editdlrm
xml.html3448840644editdlrm
xmlcatalog_man.html140720644editdlrm
xmldtd.html136470644editdlrm
XMLinfo.html67990644editdlrm
xmlio.html127970644editdlrm
xmllint.html233110644editdlrm
xmlmem.html144430644editdlrm
xmlreader.html201380644editdlrm
XSLT.html57770644editdlrm
Edit: /usr/share/doc/libxml2-devel/namespaces.html (8339B)
Namespaces
Action against software patentsGnome2 LogoW3C LogoRed Hat Logo
Made with Libxml2 Logo

The XML C parser and toolkit of Gnome

Namespaces

Main Menu
Related links

The libxml2 library implements XML namespaces support by recognizing namespace constructs in the input, and does namespace lookup automatically when building the DOM tree. A namespace declaration is associated with an in-memory structure and all elements or attributes within that namespace point to it. Hence testing the namespace is a simple and fast equality operation at the user level.

I suggest that people using libxml2 use a namespace, and declare it in the root element of their document as the default namespace. Then they don't need to use the prefix in the content but we will have a basis for future semantic refinement and merging of data from different sources. This doesn't increase the size of the XML output significantly, but significantly increases its value in the long-term. Example:

<mydoc xmlns="http://mydoc.example.org/schemas/">
   <elem1>...</elem1>
   <elem2>...</elem2>
</mydoc>

The namespace value has to be an absolute URL, but the URL doesn't have to point to any existing resource on the Web. It will bind all the element and attributes with that URL. I suggest to use an URL within a domain you control, and that the URL should contain some kind of version information if possible. For example, "http://www.gnome.org/gnumeric/1.0/" is a good namespace scheme.

Then when you load a file, make sure that a namespace carrying the version-independent prefix is installed on the root element of your document, and if the version information don't match something you know, warn the user and be liberal in what you accept as the input. Also do *not* try to base namespace checking on the prefix value. <foo:text> may be exactly the same as <bar:text> in another document. What really matters is the URI associated with the element or the attribute, not the prefix string (which is just a shortcut for the full URI). In libxml, element and attributes have an ns field pointing to an xmlNs structure detailing the namespace prefix and its URI.

@@Interfaces@@

xmlNodePtr node;
if(!strncmp(node->name,"mytag",5)
  && node->ns
  && !strcmp(node->ns->href,"http://www.mysite.com/myns/1.0")) {
  ...
}

Usually people object to using namespaces together with validity checking. I will try to make sure that using namespaces won't break validity checking, so even if you plan to use or currently are using validation I strongly suggest adding namespaces to your document. A default namespace scheme xmlns="http://...." should not break validity even on less flexible parsers. Using namespaces to mix and differentiate content coming from multiple DTDs will certainly break current validation schemes. To check such documents one needs to use schema-validation, which is supported in libxml2 as well. See relagx-ng and w3c-schema.

Daniel Veillard