Blame doc/FAQ.html

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>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 Service a31ea6
      
  • License(s)
  • Packit Service a31ea6
      
  • Installation
  • Packit Service a31ea6
      
  • Compilation
  • Packit Service a31ea6
      
  • Developer corner
  • Packit Service a31ea6

    License(s)

      Packit Service a31ea6
        
    1. Licensing Terms for libxml
    2. Packit Service a31ea6
          

      libxml2 is released under the MIT

      Packit Service a31ea6
          License; see the file Copyright in the distribution for the precise
      Packit Service a31ea6
          wording

      Packit Service a31ea6
        
      Packit Service a31ea6
        
    3. Can I embed libxml2 in a proprietary application ?
    4. Packit Service a31ea6
          

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

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

      Packit Service a31ea6
        
      Packit Service a31ea6

      Installation

        Packit Service a31ea6
          
      1. Do Not Use
      2. Packit Service a31ea6
            libxml1, use libxml2
        Packit Service a31ea6
          

        Packit Service a31ea6
          
      3. Where can I get libxml ?
      4. Packit Service a31ea6
            

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

        Packit Service a31ea6
            

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

        Packit Service a31ea6
            safer way for end-users to use libxml.

        Packit Service a31ea6
            

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

        Packit Service a31ea6
          
        Packit Service a31ea6
          

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

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

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

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

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

          Packit Service a31ea6
              rebuild it locally with

          Packit Service a31ea6
              

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

          Packit Service a31ea6
              

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

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

          Packit Service a31ea6
            
          Packit Service a31ea6

          Compilation

            Packit Service a31ea6
              
          1. What is the process to compile libxml2 ?
          2. Packit Service a31ea6
                

            As most UNIX libraries libxml2 follows the "standard":

            Packit Service a31ea6
                

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

            Packit Service a31ea6
                

            cd libxml-xxxx

            Packit Service a31ea6
                

            ./configure --help

            Packit Service a31ea6
                

            to see the options, then the compilation/installation proper

            Packit Service a31ea6
                

            ./configure [possible options]

            Packit Service a31ea6
                

            make

            Packit Service a31ea6
                

            make install

            Packit Service a31ea6
                

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

            Packit Service a31ea6
                update your list of installed shared libs.

            Packit Service a31ea6
              
            Packit Service a31ea6
              
          3. What other libraries are needed to compile/install libxml2 ?
          4. Packit Service a31ea6
                

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

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

            Packit Service a31ea6
                

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

            Packit Service a31ea6
                following libs:

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

              Packit Service a31ea6
                
            • Make check fails on some platforms
            • Packit Service a31ea6
                  

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

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

              Packit Service a31ea6
                  

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

              Packit Service a31ea6
                  in make. Try using GNU-make instead.

              Packit Service a31ea6
                
              Packit Service a31ea6
                
            • I use the SVN version and there is no configure script
            • Packit Service a31ea6
                  

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

              Packit Service a31ea6
                  autogen.sh script to regenerate the configure script and Makefiles,
              Packit Service a31ea6
                  like:

              Packit Service a31ea6
                  

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

              Packit Service a31ea6
                
              Packit Service a31ea6
                
            • I have troubles when running make tests with gcc-3.0
            • Packit Service a31ea6
                  

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

              Packit Service a31ea6
                  optimizer which miscompiles the URI module. Please use another
              Packit Service a31ea6
                  compiler.

              Packit Service a31ea6
                
              Packit Service a31ea6

              Developer corner

                Packit Service a31ea6
                  
              1. Troubles compiling or linking programs using libxml2
              2. Packit Service a31ea6
                    

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

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

                Packit Service a31ea6
                    

                xml2-config --cflags

                Packit Service a31ea6
                    

                to get the compilation flags and

                Packit Service a31ea6
                    

                xml2-config --libs

                Packit Service a31ea6
                    

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

                Packit Service a31ea6
                    Makefile as:

                Packit Service a31ea6
                    

                CFLAGS=`xml2-config --cflags`

                Packit Service a31ea6
                    

                LIBS=`xml2-config --libs`

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

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

                Packit Service a31ea6
                    do this under Linux.  Suppose your home directory is /home/user.
                Packit Service a31ea6
                    Then:

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

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

                  Packit Service a31ea6
                          configuration options}

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

                  /home/user/myxml/xmlinst/lib,

                  Packit Service a31ea6
                          /home/user/myxml/xmlinst/include  and 
                  Packit Service a31ea6
                          /home/user/myxml/xmlinst/bin

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

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

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

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

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

                  Packit Service a31ea6
                    
                • xmlDocDump() generates output on one line.
                • Packit Service a31ea6
                      

                  Libxml2 will not invent spaces in the content of a

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

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

                    Packit Service a31ea6
                      
                  5. Extra nodes in the document:
                  6. Packit Service a31ea6
                        

                    For an XML file as below:

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

                    after parsing it with the function

                    Packit Service a31ea6
                        pxmlDoc=xmlParseFile(...);

                    Packit Service a31ea6
                        

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

                    Packit Service a31ea6
                        CommFlag="0")

                    Packit Service a31ea6
                        

                    so I did it as following;

                    Packit Service a31ea6
                        
                    xmlNodePtr pnode;
                    Packit Service a31ea6
                    pnode=pxmlDoc->children->children;
                    Packit Service a31ea6
                        

                    but it does not work. If I change it to

                    Packit Service a31ea6
                        
                    pnode=pxmlDoc->children->children->next;
                    Packit Service a31ea6
                        

                    then it works. Can someone explain it to me.

                    Packit Service a31ea6
                        

                    Packit Service a31ea6
                        

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

                    Packit Service a31ea6
                        including blanks and formatting line breaks.

                    Packit Service a31ea6
                        

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

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

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

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

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

                    Packit Service a31ea6
                      
                    Packit Service a31ea6
                      
                  9. I get compilation errors about non existing
                  10. Packit Service a31ea6
                        xmlRootNode or xmlChildrenNode
                    Packit Service a31ea6
                        fields.
                    Packit Service a31ea6
                        

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

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

                    Packit Service a31ea6
                      
                    Packit Service a31ea6
                      
                  11. Random crashes in threaded applications
                  12. Packit Service a31ea6
                        

                    Read and follow all advices on the thread

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

                    Packit Service a31ea6
                      
                    Packit Service a31ea6
                      
                  13. The example provided in the web page does not compile.
                  14. Packit Service a31ea6
                        

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

                    Packit Service a31ea6
                        <grin/> ...

                    Packit Service a31ea6
                        

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

                    Packit Service a31ea6
                        patches.

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

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

                    Packit Service a31ea6
                        can:

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

                      Packit Service a31ea6
                        
                    • What about C++ ?
                    • Packit Service a31ea6
                          

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

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

                      Packit Service a31ea6
                          

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

                      Packit Service a31ea6
                          
                        Packit Service a31ea6
                              
                      • by Ari Johnson <ari@btigate.com>:
                      • Packit Service a31ea6
                                

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

                        Packit Service a31ea6
                                

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

                        Packit Service a31ea6
                              
                        Packit Service a31ea6
                            
                        Packit Service a31ea6
                          
                        Packit Service a31ea6
                          
                      • How to validate a document a posteriori ?
                      • Packit Service a31ea6
                            

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

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

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

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

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

                        Packit Service a31ea6
                          
                        Packit Service a31ea6
                          
                      • etc ...
                      • Packit Service a31ea6

                        Daniel Veillard

                        </body></html>