| Table of Contents: - Licensing Terms for libxml
libxml2 is released under the MITLicense;
see the file Copyright in the distribution for the precisewording
- Can I embed libxml2 in a proprietary application ?
Yes. The MIT License allows you to keep proprietary the changes
youmade to libxml, but it would be graceful to send-back bug fixes
andimprovements as patches for possible incorporation in the
maindevelopment tree.
- Do Not
Uselibxml1, use libxml2
- Where can I get libxml?
The original distribution comes from xmlsoft.orgor gnome.org
Most Linux and BSD distributions include libxml, this is probably
thesafer way for end-users to use libxml.
David Doolin provides precompiled Windows versions at http://www.ce.berkeley.edu/~doolin/code/libxmlwin32/
- I see libxml and libxml2 releases, which one should I install ?
- If you are not constrained by backward compatibility issues
withexisting applications, install libxml2 only
- If you are not doing development, you can safely install
both.Usually the packages libxmland libxml2arecompatible
(this is not the case for development packages).
- If you are a developer and your system provides separate
packagingfor shared libraries and the development components, it is
possibleto install libxml and libxml2, and also libxml-develand
libxml2-develtoo
for libxml2 >= 2.3.0
- If you are developing a new application, please develop
againstlibxml2(-devel)
- I can't install the libxml package, it conflicts with libxml0
You probably have an old libxml0 package used to provide the
sharedlibrary for libxml.so.0, you can probably safely remove it. The
libxmlpackages provided on xmlsoft.orgprovidelibxml.so.0
- I can't install the libxml(2) RPM package due to
faileddependencies
The most generic solution is to re-fetch the latest src.rpm ,
andrebuild it locally with
rpm --rebuild libxml(2)-xxx.src.rpm .
If everything goes well it will generate two binary rpm packages
(oneproviding the shared libs and xmllint, and the other one, the
-develpackage, providing includes, static libraries and scripts needed to
buildapplications with libxml(2)) that you can install locally.
- What is the process to compile libxml2 ?
As most UNIX libraries libxml2 follows the "standard":
gunzip -c xxx.tar.gz | tar xvf -
cd libxml-xxxx
./configure --help
to see the options, then the compilation/installation proper
./configure [possible options]
make
make install
At that point you may have to rerun ldconfig or a similar utility
toupdate your list of installed shared libs.
- What other libraries are needed to compile/install libxml2 ?
Libxml2 does not require any other library, the normal C ANSI
APIshould be sufficient (please report any violation to this rule you
mayfind).
However if found at configuration time libxml2 will detect and use
thefollowing libs:
- libz:
ahighly portable and available widely compression library.
- iconv: a powerful character encoding conversion library. It
isincluded by default in recent glibc libraries, so it doesn't need
tobe installed specifically on Linux. It now seems a partof
the official UNIXspecification. Here is one implementation of
thelibrarywhich source can be found here.
- Make check fails on some platforms
Sometimes the regression tests' results don't completely match
thevalue produced by the parser, and the makefile uses diff to print
thedelta. On some platforms the diff return breaks the compilation
process;if the diff is small this is probably not a serious problem.
Sometimes (especially on Solaris) make checks fail due to
limitationsin make. Try using GNU-make instead.
- I use the CVS version and there is no configure script
The configure script (and other Makefiles) are generated. Use
theautogen.sh script to regenerate the configure script and
Makefiles,like:
./autogen.sh --prefix=/usr --disable-shared
- I have troubles when running make tests with gcc-3.0
It seems the initial release of gcc-3.0 has a problem with
theoptimizer which miscompiles the URI module. Please use
anothercompiler.
- Troubles compiling or linking programs using libxml2
Usually the problem comes from the fact that the compiler doesn't
getthe right compilation or linking flags. There is a small shell
scriptxml2-config which is installed as part of libxml2
usualinstall process which provides those flags. Use
xml2-config --cflags
to get the compilation flags and
xml2-config --libs
to get the linker flags. Usually this is done directly from
theMakefile as:
CFLAGS=`xml2-config --cflags`
LIBS=`xml2-config --libs`
- I want to install my own copy of libxml2 in my home directory
andlink my programs against it, but it doesn't work
There are many different ways to accomplish this. Here is one way
todo this under Linux. Suppose your home directory is
/home/user. Then:
- Create a subdirectory, let's call it
myxml
- unpack the libxml2 distribution into that subdirectory
- chdir into the unpacked distribution(
/home/user/myxml/libxml2
)
- configure the library using the "
--prefix "
switch,specifying an installation subdirectory
in/home/user/myxml , e.g.
./configure --prefix
/home/user/myxml/xmlinst {otherconfiguration options}
- now run
make followed by make install
- At this point, the installation subdirectory contains the
complete"private" include files, library files and binary program
files (e.g.xmllint), located in
/home/user/myxml/xmlinst/lib,/home/user/myxml/xmlinst/include
and /home/user/myxml/xmlinst/bin
respectively.
- In order to use this "private" library, you should first add it
tothe beginning of your default PATH (so that your own private
programfiles such as xmllint will be used instead of the normal
systemones). To do this, the Bash command would be
export PATH=/home/user/myxml/xmlinst/bin:$PATH
- Now suppose you have a program
test1.c that you
wouldlike to compile with your "private" library. Simply compile it
usingthe command
gcc `xml2-config --cflags --libs` -o test test.c
Note that, because your PATH has been set with
/home/user/myxml/xmlinst/bin at the beginning, the
xml2-configprogram which you just installed will be used instead of
the systemdefault one, and this will automaticallyget the
correctlibraries linked with your program.
- xmlDocDump() generates output on one line.
Libxml2 will not inventspaces in the content of
adocument since all spaces in the content of a document
aresignificant. If you build a tree from the API and
wantindentation:
- the correct way is to generate those yourself too.
- the dangerous way is to ask libxml2 to add those blanks to
yourcontent modifying the content of your document in
theprocess. The result may not be what you expect. There
isNOway to guarantee that such a modification
won'taffect other parts of the content of your document. See xmlKeepBlanksDefault()and
xmlSaveFormatFile()
- Extra nodes in the document:
For a XML file as below:
<?xml version="1.0"?>
<PLAN xmlns="http://www.argus.ca/autotest/1.0/">
<NODE CommFlag="0"/>
<NODE CommFlag="1"/>
</PLAN>
after parsing it with the
functionpxmlDoc=xmlParseFile(...);
I want to the get the content of the first node (node with
theCommFlag="0")
so I did it as following;
xmlNodePtr pnode;
pnode=pxmlDoc->children->children;
but it does not work. If I change it to
pnode=pxmlDoc->children->children->next;
then it works. Can someone explain it to me.
In XML all characters in the content of the document are
significantincluding blanks and formatting line
breaks.
The extra nodes you are wondering about are just that, text nodes
withthe formatting spaces which are part of the document but that people
tendto forget. There is a function xmlKeepBlanksDefault()to
remove those at parse time, but that's an heuristic, and itsuse should be
limited to cases where you are certain there is nomixed-content in the
document.
- I get compilation errors of existing code like when
accessingrootor child fieldsof
nodes.
You are compiling code developed for libxml version 1 and using
alibxml2 development environment. Either switch back to libxml v1 devel
oreven better fix the code to compile with libxml2 (or both) by following the instructions.
- I get compilation errors about non
existingxmlRootNodeor
xmlChildrenNodefields.
The source code you are using has been upgradedto be able to compile with both libxmland
libxml2, but you need to install a more recent version:libxml(-devel)
>= 1.8.8 or libxml2(-devel) >= 2.1.0
- XPath implementation looks seriously broken
XPath implementation prior to 2.3.0 was really incomplete. Upgrade toa
recent version, there are no known bugs in the current version.
- The example provided in the web page does not compile.
It's hard to maintain the documentation in sync with the
code<grin/> ...
Check the previous points 1/ and 2/ raised before, and please
sendpatches.
- Where can I get more examples and information than provided on
theweb page?
Ideally a libxml2 book would be nice. I have no such plan ... But
youcan:
- check more deeply the existinggenerated doc
- have a look at the set
ofexamples.
- look for examples of use for libxml2 function using the Gnome
code.For example the following will query the full Gnome CVS base for
theuse of the xmlAddChild()function:
http://cvs.gnome.org/lxr/search?string=xmlAddChild
This may be slow, a large hardware donation to the gnome
projectcould cure this :-)
- Browsethe
libxml2 source, I try to write code as clean and documentedas
possible, so looking at it may be helpful. In particular the codeof
xmllint.c and of the various testXXX.c test programs shouldprovide
good examples of how to do things with the library.
- What about C++ ?
libxml2 is written in pure C in order to allow easy reuse on a
numberof platforms, including embedded systems. I don't intend to convert
toC++.
There is however a C++ wrapper which may fulfill your needs:
- How to validate a document a posteriori ?
It is possible to validate documents which had not been validated
atinitial parsing time or documents which have been built from
scratchusing the API. Use the xmlValidateDtd()function.
It is also possible to simply add a DTD to an existingdocument:
xmlDocPtr doc; /* your existing document */
xmlDtdPtr dtd = xmlParseDTD(NULL, filename_of_dtd); /* parse the DTD */
dtd->name = xmlStrDup((xmlChar*)"root_name"); /* use the given root */
doc->intSubset = dtd;
if (doc->children == NULL) xmlAddChild((xmlNodePtr)doc, (xmlNodePtr)dtd);
else xmlAddPrevSibling(doc->children, (xmlNodePtr)dtd);
- So what is this funky "xmlChar" used all the time?
It is a null terminated sequence of utf-8 characters. And only
utf-8!You need to convert strings encoded in different ways to utf-8
beforepassing them to the API. This can be accomplished with the iconv
libraryfor instance.
- etc ...
Daniel Veillard |
|
|
|