|
Packit Service |
a31ea6 |
|
|
Packit Service |
a31ea6 |
|
|
Packit Service |
a31ea6 |
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><link rel="SHORTCUT ICON" href="/favicon.ico" /><style type="text/css">
|
|
Packit Service |
a31ea6 |
TD {font-family: Verdana,Arial,Helvetica}
|
|
Packit Service |
a31ea6 |
BODY {font-family: Verdana,Arial,Helvetica; margin-top: 2em; margin-left: 0em; margin-right: 0em}
|
|
Packit Service |
a31ea6 |
H1 {font-family: Verdana,Arial,Helvetica}
|
|
Packit Service |
a31ea6 |
H2 {font-family: Verdana,Arial,Helvetica}
|
|
Packit Service |
a31ea6 |
H3 {font-family: Verdana,Arial,Helvetica}
|
|
Packit Service |
a31ea6 |
A:link, A:visited, A:active { text-decoration: underline }
|
|
Packit Service |
a31ea6 |
</style><title>Namespaces</title></head><body bgcolor="#8b7765" text="#000000" link="#a06060" vlink="#000000"> | | The XML C parser and toolkit of GnomeNamespaces |
|
|
<center>Main Menu</center> | <form action="search.php" enctype="application/x-www-form-urlencoded" method="get"><input name="query" type="text" size="20" value="" /><input name="submit" type="submit" value="Search ..." /></form> |
<center>Related links</center> | |
|
| |
|
|
|
Packit Service |
a31ea6 |
recognizing namespace constructs in the input, and does namespace lookup
|
|
Packit Service |
a31ea6 |
automatically when building the DOM tree. A namespace declaration is
|
|
Packit Service |
a31ea6 |
associated with an in-memory structure and all elements or attributes within
|
|
Packit Service |
a31ea6 |
that namespace point to it. Hence testing the namespace is a simple and fast
|
|
Packit Service |
a31ea6 |
equality operation at the user level.I suggest that people using libxml2 use a namespace, and declare it in the
|
|
Packit Service |
a31ea6 |
root element of their document as the default namespace. Then they don't need
|
|
Packit Service |
a31ea6 |
to use the prefix in the content but we will have a basis for future semantic
|
|
Packit Service |
a31ea6 |
refinement and merging of data from different sources. This doesn't increase
|
|
Packit Service |
a31ea6 |
the size of the XML output significantly, but significantly increases its
|
|
Packit Service |
a31ea6 |
value in the long-term. Example:<mydoc xmlns="http://mydoc.example.org/schemas/">
|
|
Packit Service |
a31ea6 |
<elem1>...</elem1>
|
|
Packit Service |
a31ea6 |
<elem2>...</elem2>
|
|
Packit Service |
a31ea6 |
</mydoc>The namespace value has to be an absolute URL, but the URL doesn't have to
|
|
Packit Service |
a31ea6 |
point to any existing resource on the Web. It will bind all the element and
|
|
Packit Service |
a31ea6 |
attributes with that URL. I suggest to use an URL within a domain you
|
|
Packit Service |
a31ea6 |
control, and that the URL should contain some kind of version information if
|
|
Packit Service |
a31ea6 |
possible. For example, "http://www.gnome.org/gnumeric/1.0/" is a
|
|
Packit Service |
a31ea6 |
good namespace scheme.Then when you load a file, make sure that a namespace carrying the
|
|
Packit Service |
a31ea6 |
version-independent prefix is installed on the root element of your document,
|
|
Packit Service |
a31ea6 |
and if the version information don't match something you know, warn the user
|
|
Packit Service |
a31ea6 |
and be liberal in what you accept as the input. Also do *not* try to base
|
|
Packit Service |
a31ea6 |
namespace checking on the prefix value. <foo:text> may be exactly the
|
|
Packit Service |
a31ea6 |
same as <bar:text> in another document. What really matters is the URI
|
|
Packit Service |
a31ea6 |
associated with the element or the attribute, not the prefix string (which is
|
|
Packit Service |
a31ea6 |
just a shortcut for the full URI). In libxml, element and attributes have an
|
|
Packit Service |
a31ea6 |
ns field pointing to an xmlNs structure detailing the namespace
|
|
Packit Service |
a31ea6 |
prefix and its URI.@@Interfaces@@ xmlNodePtr node;
|
|
Packit Service |
a31ea6 |
if(!strncmp(node->name,"mytag",5)
|
|
Packit Service |
a31ea6 |
&& node->ns
|
|
Packit Service |
a31ea6 |
&& !strcmp(node->ns->href,"http://www.mysite.com/myns/1.0")) {
|
|
Packit Service |
a31ea6 |
...
|
|
Packit Service |
a31ea6 |
}Usually people object to using namespaces together with validity checking.
|
|
Packit Service |
a31ea6 |
I will try to make sure that using namespaces won't break validity checking,
|
|
Packit Service |
a31ea6 |
so even if you plan to use or currently are using validation I strongly
|
|
Packit Service |
a31ea6 |
suggest adding namespaces to your document. A default namespace scheme
|
|
Packit Service |
a31ea6 |
xmlns="http://...." should not break validity even on less
|
|
Packit Service |
a31ea6 |
flexible parsers. Using namespaces to mix and differentiate content coming
|
|
Packit Service |
a31ea6 |
from multiple DTDs will certainly break current validation schemes. To check
|
|
Packit Service |
a31ea6 |
such documents one needs to use schema-validation, which is supported in
|
|
Packit Service |
a31ea6 |
libxml2 as well. See relagx-ng and w3c-schema.Daniel Veillard </body></html>
|