Action against software patentsGnome2 LogoW3C LogoRed Hat Logo
Made with Libxml2 Logo

The XML C parser and toolkit of Gnome

FAQ

Main Menu
Related links

Table of Contents:

License(s)

  1. Licensing Terms for libxml

    libxml2 is released under the MITLicense;see the file Copyright in the distribution for the precisewording

  2. Can I embed libxml2 in a proprietary application ?

    Yes. The MIT License allows you to keep proprietary the changesyoumade to libxml, but it would be graceful to send-back bug fixesandimprovements as patches for possible incorporation in themaindevelopment tree.

Installation

  1. Do NotUselibxml1, use libxml2
  2. Where can I get libxml?

    The original distribution comes from xmlsoft.orgor gnome.org

    Most Linux and BSD distributions include libxml, this is probablythesafer way for end-users to use libxml.

    David Doolin provides precompiled Windows versions at http://www.ce.berkeley.edu/~doolin/code/libxmlwin32/

  3. I see libxml and libxml2 releases, which one should I install ?
    • If you are not constrained by backward compatibility issueswithexisting applications, install libxml2 only
    • If you are not doing development, you can safely installboth.Usually the packages libxmland libxml2arecompatible(this is not the case for development packages).
    • If you are a developer and your system provides separatepackagingfor shared libraries and the development components, it ispossibleto install libxml and libxml2, and also libxml-develandlibxml2-develtoofor libxml2 >= 2.3.0
    • If you are developing a new application, please developagainstlibxml2(-devel)
  4. I can't install the libxml package, it conflicts with libxml0

    You probably have an old libxml0 package used to provide thesharedlibrary for libxml.so.0, you can probably safely remove it. Thelibxmlpackages provided on xmlsoft.orgprovidelibxml.so.0

  5. I can't install the libxml(2) RPM package due tofaileddependencies

    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 tobuildapplications with libxml(2)) that you can install locally.

Compilation

  1. 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 utilitytoupdate your list of installed shared libs.

  2. What other libraries are needed to compile/install libxml2 ?

    Libxml2 does not require any other library, the normal C ANSIAPIshould be sufficient (please report any violation to this rule youmayfind).

    However if found at configuration time libxml2 will detect and usethefollowing libs:

    • libz:ahighly portable and available widely compression library.
    • iconv: a powerful character encoding conversion library. Itisincluded by default in recent glibc libraries, so it doesn't needtobe installed specifically on Linux. It now seems a partofthe official UNIXspecification. Here is one implementation ofthelibrarywhich source can be found here.
  3. Make check fails on some platforms

    Sometimes the regression tests' results don't completely matchthevalue produced by the parser, and the makefile uses diff to printthedelta. On some platforms the diff return breaks the compilationprocess;if the diff is small this is probably not a serious problem.

    Sometimes (especially on Solaris) make checks fail due tolimitationsin make. Try using GNU-make instead.

  4. I use the CVS version and there is no configure script

    The configure script (and other Makefiles) are generated. Usetheautogen.sh script to regenerate the configure script andMakefiles,like:

    ./autogen.sh --prefix=/usr --disable-shared

  5. I have troubles when running make tests with gcc-3.0

    It seems the initial release of gcc-3.0 has a problem withtheoptimizer which miscompiles the URI module. Please useanothercompiler.

Developercorner

  1. Troubles compiling or linking programs using libxml2

    Usually the problem comes from the fact that the compiler doesn'tgetthe right compilation or linking flags. There is a small shellscriptxml2-configwhich is installed as part of libxml2usualinstall 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 fromtheMakefile as:

    CFLAGS=`xml2-config --cflags`

    LIBS=`xml2-config --libs`

  2. I want to install my own copy of libxml2 in my home directoryandlink my programs against it, but it doesn't work

    There are many different ways to accomplish this. Here is one waytodo 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 subdirectoryin/home/user/myxml, e.g.

      ./configure --prefix/home/user/myxml/xmlinst{otherconfiguration options}

    • now run makefollowed by make install
    • At this point, the installation subdirectory contains thecomplete"private" include files, library files and binary programfiles (e.g.xmllint), located in

      /home/user/myxml/xmlinst/lib,/home/user/myxml/xmlinst/includeand /home/user/myxml/xmlinst/bin

      respectively.
    • In order to use this "private" library, you should first add ittothe beginning of your default PATH (so that your own privateprogramfiles such as xmllint will be used instead of the normalsystemones). To do this, the Bash command would be

      export PATH=/home/user/myxml/xmlinst/bin:$PATH

    • Now suppose you have a program test1.cthat youwouldlike to compile with your "private" library. Simply compile itusingthe command

      gcc `xml2-config --cflags --libs` -o test test.c

      Note that, because your PATH has been set with/home/user/myxml/xmlinst/binat the beginning, thexml2-configprogram which you just installed will be used instead ofthe systemdefault one, and this will automaticallyget thecorrectlibraries linked with your program.
  3. xmlDocDump() generates output on one line.

    Libxml2 will not inventspaces in the content ofadocument since all spaces in the content of a documentaresignificant. If you build a tree from the API andwantindentation:

    1. the correct way is to generate those yourself too.
    2. the dangerous way is to ask libxml2 to add those blanks toyourcontent modifying the content of your document intheprocess. The result may not be what you expect. ThereisNOway to guarantee that such a modificationwon'taffect other parts of the content of your document. See xmlKeepBlanksDefault()andxmlSaveFormatFile()
  4. 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 thefunctionpxmlDoc=xmlParseFile(...);

    I want to the get the content of the first node (node withtheCommFlag="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 aresignificantincluding blanks and formatting linebreaks.

    The extra nodes you are wondering about are just that, text nodeswiththe formatting spaces which are part of the document but that peopletendto forget. There is a function xmlKeepBlanksDefault()toremove those at parse time, but that's an heuristic, and itsuse should belimited to cases where you are certain there is nomixed-content in thedocument.

  5. I get compilation errors of existing code like whenaccessingrootor child fieldsofnodes.

    You are compiling code developed for libxml version 1 and usingalibxml2 development environment. Either switch back to libxml v1 develoreven better fix the code to compile with libxml2 (or both) by following the instructions.

  6. I get compilation errors about nonexistingxmlRootNodeorxmlChildrenNodefields.

    The source code you are using has been upgradedto be able to compile with both libxmlandlibxml2, but you need to install a more recent version:libxml(-devel)>= 1.8.8 or libxml2(-devel) >= 2.1.0

  7. XPath implementation looks seriously broken

    XPath implementation prior to 2.3.0 was really incomplete. Upgrade toarecent version, there are no known bugs in the current version.

  8. The example provided in the web page does not compile.

    It's hard to maintain the documentation in sync with thecode<grin/> ...

    Check the previous points 1/ and 2/ raised before, and pleasesendpatches.

  9. Where can I get more examples and information than provided ontheweb page?

    Ideally a libxml2 book would be nice. I have no such plan ... Butyoucan:

    • check more deeply the existinggenerated doc
    • have a look at the setofexamples.
    • look for examples of use for libxml2 function using the Gnomecode.For example the following will query the full Gnome CVS base fortheuse of the xmlAddChild()function:

      http://cvs.gnome.org/lxr/search?string=xmlAddChild

      This may be slow, a large hardware donation to the gnomeprojectcould cure this :-)

    • Browsethelibxml2 source, I try to write code as clean and documentedaspossible, so looking at it may be helpful. In particular the codeofxmllint.c and of the various testXXX.c test programs shouldprovidegood examples of how to do things with the library.
  10. What about C++ ?

    libxml2 is written in pure C in order to allow easy reuse on anumberof platforms, including embedded systems. I don't intend to converttoC++.

    There is however a C++ wrapper which may fulfill your needs:

  11. How to validate a document a posteriori ?

    It is possible to validate documents which had not been validatedatinitial parsing time or documents which have been built fromscratchusing 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);
              
  12. So what is this funky "xmlChar" used all the time?

    It is a null terminated sequence of utf-8 characters. And onlyutf-8!You need to convert strings encoded in different ways to utf-8beforepassing them to the API. This can be accomplished with the iconvlibraryfor instance.

  13. etc ...

Daniel Veillard