Blame doc/FAQ.html

Packit 423ecb
Packit 423ecb
Packit 423ecb
<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 423ecb
TD {font-family: Verdana,Arial,Helvetica}
Packit 423ecb
BODY {font-family: Verdana,Arial,Helvetica; margin-top: 2em; margin-left: 0em; margin-right: 0em}
Packit 423ecb
H1 {font-family: Verdana,Arial,Helvetica}
Packit 423ecb
H2 {font-family: Verdana,Arial,Helvetica}
Packit 423ecb
H3 {font-family: Verdana,Arial,Helvetica}
Packit 423ecb
A:link, A:visited, A:active { text-decoration: underline }
Packit 423ecb
</style><title>FAQ</title></head><body bgcolor="#8b7765" text="#000000" link="#a06060" vlink="#000000">
Action against software patentsGnome2 LogoW3C LogoRed Hat Logo
Made with Libxml2 Logo

The XML C parser and toolkit of Gnome

FAQ

<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>

Table of Contents:

    Packit 423ecb
      
  • License(s)
  • Packit 423ecb
      
  • Installation
  • Packit 423ecb
      
  • Compilation
  • Packit 423ecb
      
  • Developer corner
  • Packit 423ecb

    License(s)

      Packit 423ecb
        
    1. Licensing Terms for libxml
    2. Packit 423ecb
          

      libxml2 is released under the MIT

      Packit 423ecb
          License; see the file Copyright in the distribution for the precise
      Packit 423ecb
          wording

      Packit 423ecb
        
      Packit 423ecb
        
    3. Can I embed libxml2 in a proprietary application ?
    4. Packit 423ecb
          

      Yes. The MIT License allows you to keep proprietary the changes you

      Packit 423ecb
          made to libxml, but it would be graceful to send-back bug fixes and
      Packit 423ecb
          improvements as patches for possible incorporation in the main
      Packit 423ecb
          development tree.

      Packit 423ecb
        
      Packit 423ecb

      Installation

        Packit 423ecb
          
      1. Do Not Use
      2. Packit 423ecb
            libxml1, use libxml2
        Packit 423ecb
          

        Packit 423ecb
          
      3. Where can I get libxml ?
      4. Packit 423ecb
            

        The original distribution comes from xmlsoft.org or gnome.org

        Packit 423ecb
            

        Most Linux and BSD distributions include libxml, this is probably the

        Packit 423ecb
            safer way for end-users to use libxml.

        Packit 423ecb
            

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

        Packit 423ecb
          
        Packit 423ecb
          

        Packit 423ecb
          
      5. I see libxml and libxml2 releases, which one should I install ?
      6. Packit 423ecb
            
          Packit 423ecb
                
        • If you are not constrained by backward compatibility issues with
        • Packit 423ecb
                  existing applications, install libxml2 only
          Packit 423ecb
                
        • If you are not doing development, you can safely install both.
        • Packit 423ecb
                  Usually the packages libxml and libxml2 are
          Packit 423ecb
                  compatible (this is not the case for development packages).
          Packit 423ecb
                
        • If you are a developer and your system provides separate packaging
        • Packit 423ecb
                  for shared libraries and the development components, it is possible
          Packit 423ecb
                  to install libxml and libxml2, and also libxml-devel
          Packit 423ecb
                  and libxml2-devel
          Packit 423ecb
                  too for libxml2 >= 2.3.0
          Packit 423ecb
                
        • If you are developing a new application, please develop against
        • Packit 423ecb
                  libxml2(-devel)
          Packit 423ecb
              
          Packit 423ecb
            
          Packit 423ecb
            
        • I can't install the libxml package, it conflicts with libxml0
        • Packit 423ecb
              

          You probably have an old libxml0 package used to provide the shared

          Packit 423ecb
              library for libxml.so.0, you can probably safely remove it. The libxml
          Packit 423ecb
              packages provided on xmlsoft.org provide
          Packit 423ecb
              libxml.so.0

          Packit 423ecb
            
          Packit 423ecb
            
        • I can't install the libxml(2) RPM package due to failed
        • Packit 423ecb
              dependencies
          Packit 423ecb
              

          The most generic solution is to re-fetch the latest src.rpm , and

          Packit 423ecb
              rebuild it locally with

          Packit 423ecb
              

          rpm --rebuild libxml(2)-xxx.src.rpm.

          Packit 423ecb
              

          If everything goes well it will generate two binary rpm packages (one

          Packit 423ecb
              providing the shared libs and xmllint, and the other one, the -devel
          Packit 423ecb
              package, providing includes, static libraries and scripts needed to build
          Packit 423ecb
              applications with libxml(2)) that you can install locally.

          Packit 423ecb
            
          Packit 423ecb

          Compilation

            Packit 423ecb
              
          1. What is the process to compile libxml2 ?
          2. Packit 423ecb
                

            As most UNIX libraries libxml2 follows the "standard":

            Packit 423ecb
                

            gunzip -c xxx.tar.gz | tar xvf -

            Packit 423ecb
                

            cd libxml-xxxx

            Packit 423ecb
                

            ./configure --help

            Packit 423ecb
                

            to see the options, then the compilation/installation proper

            Packit 423ecb
                

            ./configure [possible options]

            Packit 423ecb
                

            make

            Packit 423ecb
                

            make install

            Packit 423ecb
                

            At that point you may have to rerun ldconfig or a similar utility to

            Packit 423ecb
                update your list of installed shared libs.

            Packit 423ecb
              
            Packit 423ecb
              
          3. What other libraries are needed to compile/install libxml2 ?
          4. Packit 423ecb
                

            Libxml2 does not require any other library, the normal C ANSI API

            Packit 423ecb
                should be sufficient (please report any violation to this rule you may
            Packit 423ecb
                find).

            Packit 423ecb
                

            However if found at configuration time libxml2 will detect and use the

            Packit 423ecb
                following libs:

            Packit 423ecb
                
              Packit 423ecb
                    
            • libz : a
            • Packit 423ecb
                      highly portable and available widely compression library.
              Packit 423ecb
                    
            • iconv: a powerful character encoding conversion library. It is
            • Packit 423ecb
                      included by default in recent glibc libraries, so it doesn't need to
              Packit 423ecb
                      be installed specifically on Linux. It now seems a part
              Packit 423ecb
                      of the official UNIX specification. Here is one implementation of the
              Packit 423ecb
                      library which source can be found here.
              Packit 423ecb
                  
              Packit 423ecb
                
              Packit 423ecb
                

              Packit 423ecb
                
            • Make check fails on some platforms
            • Packit 423ecb
                  

              Sometimes the regression tests' results don't completely match the

              Packit 423ecb
                  value produced by the parser, and the makefile uses diff to print the
              Packit 423ecb
                  delta. On some platforms the diff return breaks the compilation process;
              Packit 423ecb
                  if the diff is small this is probably not a serious problem.

              Packit 423ecb
                  

              Sometimes (especially on Solaris) make checks fail due to limitations

              Packit 423ecb
                  in make. Try using GNU-make instead.

              Packit 423ecb
                
              Packit 423ecb
                
            • I use the SVN version and there is no configure script
            • Packit 423ecb
                  

              The configure script (and other Makefiles) are generated. Use the

              Packit 423ecb
                  autogen.sh script to regenerate the configure script and Makefiles,
              Packit 423ecb
                  like:

              Packit 423ecb
                  

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

              Packit 423ecb
                
              Packit 423ecb
                
            • I have troubles when running make tests with gcc-3.0
            • Packit 423ecb
                  

              It seems the initial release of gcc-3.0 has a problem with the

              Packit 423ecb
                  optimizer which miscompiles the URI module. Please use another
              Packit 423ecb
                  compiler.

              Packit 423ecb
                
              Packit 423ecb

              Developer corner

                Packit 423ecb
                  
              1. Troubles compiling or linking programs using libxml2
              2. Packit 423ecb
                    

                Usually the problem comes from the fact that the compiler doesn't get

                Packit 423ecb
                    the right compilation or linking flags. There is a small shell script
                Packit 423ecb
                    xml2-config which is installed as part of libxml2 usual
                Packit 423ecb
                    install process which provides those flags. Use

                Packit 423ecb
                    

                xml2-config --cflags

                Packit 423ecb
                    

                to get the compilation flags and

                Packit 423ecb
                    

                xml2-config --libs

                Packit 423ecb
                    

                to get the linker flags. Usually this is done directly from the

                Packit 423ecb
                    Makefile as:

                Packit 423ecb
                    

                CFLAGS=`xml2-config --cflags`

                Packit 423ecb
                    

                LIBS=`xml2-config --libs`

                Packit 423ecb
                  
                Packit 423ecb
                  
              3. I want to install my own copy of libxml2 in my home directory and
              4. Packit 423ecb
                    link my programs against it, but it doesn't work
                Packit 423ecb
                    

                There are many different ways to accomplish this. Here is one way to

                Packit 423ecb
                    do this under Linux.  Suppose your home directory is /home/user.
                Packit 423ecb
                    Then:

                Packit 423ecb
                    
                  Packit 423ecb
                        
                • Create a subdirectory, let's call it myxml
                • Packit 423ecb
                        
                • unpack the libxml2 distribution into that subdirectory
                • Packit 423ecb
                        
                • chdir into the unpacked distribution
                • Packit 423ecb
                          (/home/user/myxml/libxml2 )
                  Packit 423ecb
                        
                • configure the library using the "--prefix" switch,
                • Packit 423ecb
                          specifying an installation subdirectory in
                  Packit 423ecb
                          /home/user/myxml, e.g.
                  Packit 423ecb
                          

                  ./configure --prefix /home/user/myxml/xmlinst {other

                  Packit 423ecb
                          configuration options}

                  Packit 423ecb
                        
                  Packit 423ecb
                        
                • now run make followed by make install
                • Packit 423ecb
                        
                • At this point, the installation subdirectory contains the complete
                • Packit 423ecb
                          "private" include files, library files and binary program files (e.g.
                  Packit 423ecb
                          xmllint), located in
                  Packit 423ecb
                          

                  /home/user/myxml/xmlinst/lib,

                  Packit 423ecb
                          /home/user/myxml/xmlinst/include  and 
                  Packit 423ecb
                          /home/user/myxml/xmlinst/bin

                  Packit 423ecb
                          respectively.
                  Packit 423ecb
                        
                • In order to use this "private" library, you should first add it to
                • Packit 423ecb
                          the beginning of your default PATH (so that your own private program
                  Packit 423ecb
                          files such as xmllint will be used instead of the normal system
                  Packit 423ecb
                          ones).  To do this, the Bash command would be
                  Packit 423ecb
                          

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

                  Packit 423ecb
                        
                  Packit 423ecb
                        
                • Now suppose you have a program test1.c that you would
                • Packit 423ecb
                          like to compile with your "private" library.  Simply compile it using
                  Packit 423ecb
                          the command
                  Packit 423ecb
                          

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

                  Packit 423ecb
                          Note that, because your PATH has been set with 
                  Packit 423ecb
                          /home/user/myxml/xmlinst/bin at the beginning, the xml2-config
                  Packit 423ecb
                          program which you just installed will be used instead of the system
                  Packit 423ecb
                          default one, and this will automatically get the correct
                  Packit 423ecb
                          libraries linked with your program.
                  Packit 423ecb
                      
                  Packit 423ecb
                    
                  Packit 423ecb
                  Packit 423ecb
                    

                  Packit 423ecb
                    
                • xmlDocDump() generates output on one line.
                • Packit 423ecb
                      

                  Libxml2 will not invent spaces in the content of a

                  Packit 423ecb
                      document since all spaces in the content of a document are
                  Packit 423ecb
                      significant. If you build a tree from the API and want
                  Packit 423ecb
                      indentation:

                  Packit 423ecb
                      
                    Packit 423ecb
                          
                  1. the correct way is to generate those yourself too.
                  2. Packit 423ecb
                          
                  3. the dangerous way is to ask libxml2 to add those blanks to your
                  4. Packit 423ecb
                            content modifying the content of your document in the
                    Packit 423ecb
                            process. The result may not be what you expect. There is
                    Packit 423ecb
                            NO way to guarantee that such a modification won't
                    Packit 423ecb
                            affect other parts of the content of your document. See xmlKeepBlanksDefault
                    Packit 423ecb
                            () and xmlSaveFormatFile
                    Packit 423ecb
                            ()
                    Packit 423ecb
                        
                    Packit 423ecb
                      
                    Packit 423ecb
                      

                    Packit 423ecb
                      
                  5. Extra nodes in the document:
                  6. Packit 423ecb
                        

                    For an XML file as below:

                    Packit 423ecb
                        
                    <?xml version="1.0"?>
                    Packit 423ecb
                    <PLAN xmlns="http://www.argus.ca/autotest/1.0/">
                    Packit 423ecb
                    <NODE CommFlag="0"/>
                    Packit 423ecb
                    <NODE CommFlag="1"/>
                    Packit 423ecb
                    </PLAN>
                    Packit 423ecb
                        

                    after parsing it with the function

                    Packit 423ecb
                        pxmlDoc=xmlParseFile(...);

                    Packit 423ecb
                        

                    I want to the get the content of the first node (node with the

                    Packit 423ecb
                        CommFlag="0")

                    Packit 423ecb
                        

                    so I did it as following;

                    Packit 423ecb
                        
                    xmlNodePtr pnode;
                    Packit 423ecb
                    pnode=pxmlDoc->children->children;
                    Packit 423ecb
                        

                    but it does not work. If I change it to

                    Packit 423ecb
                        
                    pnode=pxmlDoc->children->children->next;
                    Packit 423ecb
                        

                    then it works. Can someone explain it to me.

                    Packit 423ecb
                        

                    Packit 423ecb
                        

                    In XML all characters in the content of the document are significant

                    Packit 423ecb
                        including blanks and formatting line breaks.

                    Packit 423ecb
                        

                    The extra nodes you are wondering about are just that, text nodes with

                    Packit 423ecb
                        the formatting spaces which are part of the document but that people tend
                    Packit 423ecb
                        to forget. There is a function xmlKeepBlanksDefault
                    Packit 423ecb
                        ()  to remove those at parse time, but that's an heuristic, and its
                    Packit 423ecb
                        use should be limited to cases where you are certain there is no
                    Packit 423ecb
                        mixed-content in the document.

                    Packit 423ecb
                      
                    Packit 423ecb
                      
                  7. I get compilation errors of existing code like when accessing
                  8. Packit 423ecb
                        root or child fields of nodes.
                    Packit 423ecb
                        

                    You are compiling code developed for libxml version 1 and using a

                    Packit 423ecb
                        libxml2 development environment. Either switch back to libxml v1 devel or
                    Packit 423ecb
                        even better fix the code to compile with libxml2 (or both) by following the instructions.

                    Packit 423ecb
                      
                    Packit 423ecb
                      
                  9. I get compilation errors about non existing
                  10. Packit 423ecb
                        xmlRootNode or xmlChildrenNode
                    Packit 423ecb
                        fields.
                    Packit 423ecb
                        

                    The source code you are using has been upgraded to be able to compile with both libxml

                    Packit 423ecb
                        and libxml2, but you need to install a more recent version:
                    Packit 423ecb
                        libxml(-devel) >= 1.8.8 or libxml2(-devel) >= 2.1.0

                    Packit 423ecb
                      
                    Packit 423ecb
                      
                  11. Random crashes in threaded applications
                  12. Packit 423ecb
                        

                    Read and follow all advices on the thread

                    Packit 423ecb
                        safety page, and make 100% sure you never call xmlCleanupParser()
                    Packit 423ecb
                        while the library or an XML document might still be in use by another
                    Packit 423ecb
                        thread.

                    Packit 423ecb
                      
                    Packit 423ecb
                      
                  13. The example provided in the web page does not compile.
                  14. Packit 423ecb
                        

                    It's hard to maintain the documentation in sync with the code

                    Packit 423ecb
                        <grin/> ...

                    Packit 423ecb
                        

                    Check the previous points 1/ and 2/ raised before, and please send

                    Packit 423ecb
                        patches.

                    Packit 423ecb
                      
                    Packit 423ecb
                      
                  15. Where can I get more examples and information than provided on the
                  16. Packit 423ecb
                        web page?
                    Packit 423ecb
                        

                    Ideally a libxml2 book would be nice. I have no such plan ... But you

                    Packit 423ecb
                        can:

                    Packit 423ecb
                        
                      Packit 423ecb
                            
                    • check more deeply the existing
                    • Packit 423ecb
                              generated doc
                      Packit 423ecb
                            
                    • have a look at the set of
                    • Packit 423ecb
                              examples.
                      Packit 423ecb
                            
                    • look for examples of use for libxml2 function using the Gnome code
                    • Packit 423ecb
                                or by asking on Google.
                      Packit 423ecb
                            
                    • Browse
                    • Packit 423ecb
                              the libxml2 source , I try to write code as clean and documented
                      Packit 423ecb
                              as possible, so looking at it may be helpful. In particular the code
                      Packit 423ecb
                              of xmllint.c and of the various testXXX.c test programs should
                      Packit 423ecb
                              provide good examples of how to do things with the library.
                      Packit 423ecb
                          
                      Packit 423ecb
                        
                      Packit 423ecb
                        

                      Packit 423ecb
                        
                    • What about C++ ?
                    • Packit 423ecb
                          

                      libxml2 is written in pure C in order to allow easy reuse on a number

                      Packit 423ecb
                          of platforms, including embedded systems. I don't intend to convert to
                      Packit 423ecb
                          C++.

                      Packit 423ecb
                          

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

                      Packit 423ecb
                          
                        Packit 423ecb
                              
                      • by Ari Johnson <ari@btigate.com>:
                      • Packit 423ecb
                                

                        Website: http://libxmlplusplus.sourceforge.net/

                        Packit 423ecb
                                

                        Download: http://sourceforge.net/project/showfiles.php?group_id=12999

                        Packit 423ecb
                              
                        Packit 423ecb
                            
                        Packit 423ecb
                          
                        Packit 423ecb
                          
                      • How to validate a document a posteriori ?
                      • Packit 423ecb
                            

                        It is possible to validate documents which had not been validated at

                        Packit 423ecb
                            initial parsing time or documents which have been built from scratch
                        Packit 423ecb
                            using the API. Use the xmlValidateDtd()
                        Packit 423ecb
                            function. It is also possible to simply add a DTD to an existing
                        Packit 423ecb
                            document:

                        Packit 423ecb
                            
                        xmlDocPtr doc; /* your existing document */
                        Packit 423ecb
                        xmlDtdPtr dtd = xmlParseDTD(NULL, filename_of_dtd); /* parse the DTD */
                        Packit 423ecb
                        Packit 423ecb
                                dtd->name = xmlStrDup((xmlChar*)"root_name"); /* use the given root */
                        Packit 423ecb
                        Packit 423ecb
                                doc->intSubset = dtd;
                        Packit 423ecb
                                if (doc->children == NULL) xmlAddChild((xmlNodePtr)doc, (xmlNodePtr)dtd);
                        Packit 423ecb
                                else xmlAddPrevSibling(doc->children, (xmlNodePtr)dtd);
                        Packit 423ecb
                                  
                        Packit 423ecb
                          
                        Packit 423ecb
                          
                      • So what is this funky "xmlChar" used all the time?
                      • Packit 423ecb
                            

                        It is a null terminated sequence of utf-8 characters. And only utf-8!

                        Packit 423ecb
                            You need to convert strings encoded in different ways to utf-8 before
                        Packit 423ecb
                            passing them to the API.  This can be accomplished with the iconv library
                        Packit 423ecb
                            for instance.

                        Packit 423ecb
                          
                        Packit 423ecb
                          
                      • etc ...
                      • Packit 423ecb

                        Daniel Veillard

                        </body></html>