[libxml2.wiki] Create FAQ



commit 50eafe59d812bcd07dbca50380f80795d5c08b8c
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Sat Feb 12 17:53:15 2022 +0000

    Create FAQ

 FAQ.md | 205 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 205 insertions(+)
---
diff --git a/FAQ.md b/FAQ.md
new file mode 100644
index 0000000..e1df0d1
--- /dev/null
+++ b/FAQ.md
@@ -0,0 +1,205 @@
+### License(s)
+
+1. _Licensing Terms for libxml_
+
+   libxml2 is released under the [MIT License](http://www.opensource.org/licenses/mit-license.html); see the 
file Copyright in the distribution for the precise wording
+2. _Can I embed libxml2 in a proprietary application ?_
+
+   Yes. The MIT License allows you to keep proprietary the changes you made to libxml, but it would be 
graceful to send-back bug fixes and improvements as patches for possible incorporation in the main 
development tree.
+
+### Installation
+
+1. **<span dir="">Do Not Use libxml1</span>**, use libxml2
+2. _Where can I get libxml_ ?
+
+   The original distribution comes from [xmlsoft.org](http://xmlsoft.org) or [gnome.org](http://gnome.org)
+
+   Most Linux and BSD distributions include libxml, this is probably the safer 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 issues with existing applications, install libxml2 
only
+   * If you are not doing development, you can safely install both. Usually the packages 
[libxml](http://rpmfind.net/linux/RPM/libxml.html) and [libxml2](http://rpmfind.net/linux/RPM/libxml2.html) 
are compatible (this is not the case for development packages).
+   * If you are a developer and your system provides separate packaging for shared libraries and the 
development components, it is possible to install libxml and libxml2, and also 
[libxml-devel](http://rpmfind.net/linux/RPM/libxml-devel.html) and 
[libxml2-devel](http://rpmfind.net/linux/RPM/libxml2-devel.html) too for libxml2 >= 2.3.0
+   * If you are developing a new application, please develop against libxml2(-devel)
+4. _I can't install the libxml package, it conflicts with libxml0_
+
+   You probably have an old libxml0 package used to provide the shared library for 
[libxml.so](http://libxml.so).0, you can probably safely remove it. The libxml packages provided on 
[xmlsoft.org](http://xmlsoft.org) provide [libxml.so](http://libxml.so).0
+5. _I can't install the libxml(2) RPM package due to failed dependencies_
+
+   The most generic solution is to re-fetch the latest src.rpm , and rebuild it locally with
+
+   `rpm --rebuild libxml(2)-xxx.src.rpm`.
+
+   If everything goes well it will generate two binary rpm packages (one providing the shared libs and 
xmllint, and the other one, the -devel package, providing includes, static libraries and scripts needed to 
build applications 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 utility to update 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 ANSI API should be sufficient (please report any 
violation to this rule you may find).
+
+   However if found at configuration time libxml2 will detect and use the following libs:
+   * [libz](http://www.info-zip.org/pub/infozip/zlib/) : a highly portable and available widely compression 
library.
+   * iconv: a powerful character encoding conversion library. It is included by default in recent glibc 
libraries, so it doesn't need to be installed specifically on Linux. It now seems a [part of the official 
UNIX](http://www.opennc.org/onlinepubs/7908799/xsh/iconv.html) specification. Here is one [implementation of 
the library](http://www.gnu.org/software/libiconv/) which source can be found 
[here](ftp://ftp.ilog.fr/pub/Users/haible/gnu/).
+3. _Make check fails on some platforms_
+
+   Sometimes the regression tests' results don't completely match the value produced by the parser, and the 
makefile uses diff to print the delta. 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 limitations in make. Try using GNU-make instead.
+4. _I use the SVN version and there is no configure script_
+
+   The configure script (and other Makefiles) are generated. Use the [autogen.sh](http://autogen.sh) script 
to regenerate the configure script and Makefiles, like:
+
+   `./`[`autogen.sh`](http://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 with the optimizer which miscompiles the URI 
module. Please use another compiler.
+
+### Developer corner
+
+ 1. _Troubles compiling or linking programs using libxml2_
+
+    Usually the problem comes from the fact that the compiler doesn't get the right compilation or linking 
flags. There is a small shell script `xml2-config` which is installed as part of libxml2 usual install 
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 the Makefile as:
+
+    `` CFLAGS=`xml2-config --cflags` ``
+
+    `` LIBS=`xml2-config --libs` ``
+ 2. _I want to install my own copy of libxml2 in my home directory and link my programs against it, but it 
doesn't work_
+
+    There are many different ways to accomplish this. Here is one way to do 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` {other configuration 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 to the beginning of your default PATH 
(so that your own private program files such as xmllint will be used instead of the normal system ones). 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 would like to compile with your "private" library. 
Simply compile it using the 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-config program which you just installed will be used instead of the system default one, and this will 
_automatically_ get the correct libraries linked with your program.
+ 3. _xmlDocDump() generates output on one line._
+
+    Libxml2 will not **invent** spaces in the content of a document since **all spaces in the content of a 
document are significant**. If you build a tree from the API and want indentation:
+    1. the correct way is to generate those yourself too.
+    2. the dangerous way is to ask libxml2 to add those blanks to your content **modifying the content of 
your document in the process**. The result may not be what you expect. There is **NO** way to guarantee that 
such a modification won't affect other parts of the content of your document. See [xmlKeepBlanksDefault 
()](http://xmlsoft.org/html/libxml-parser.html#xmlKeepBlanksDefault) and [xmlSaveFormatFile 
()](http://xmlsoft.org/html/libxml-tree.html#xmlSaveFormatFile)
+ 4. _Extra nodes in the document:_
+
+    _For an 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 function pxmlDoc=xmlParseFile(...);_
+
+    _I want to the get the content of the first node (node with the CommFlag="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 significant **including blanks and formatting 
line breaks**.
+
+    The extra nodes you are wondering about are just that, text nodes with the formatting spaces which are 
part of the document but that people tend to forget. There is a function [xmlKeepBlanksDefault 
()](http://xmlsoft.org/html/libxml-parser.html) to remove those at parse time, but that's an heuristic, and 
its use should be limited to cases where you are certain there is no mixed-content in the document.
+ 5. _I get compilation errors of existing code like when accessing **root** or **child fields** of nodes._
+
+    You are compiling code developed for libxml version 1 and using a libxml2 development environment. 
Either switch back to libxml v1 devel or even better fix the code to compile with libxml2 (or both) by 
[following the instructions](http://xmlsoft.org/upgrade.html).
+ 6. _I get compilation errors about non existing **xmlRootNode** or **xmlChildrenNode** fields._
+
+    The source code you are using has been [upgraded](http://xmlsoft.org/upgrade.html) to be able to compile 
with both libxml and libxml2, but you need to install a more recent version: libxml(-devel) >= 1.8.8 or 
libxml2(-devel) >= 2.1.0
+ 7. _Random crashes in threaded applications_
+
+    Read and follow all advices on the [thread safety](http://xmlsoft.org/threads.html) page, and make 100% 
sure you never call xmlCleanupParser() while the library or an XML document might still be in use by another 
thread.
+ 8. _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 send patches.
+ 9. _Where can I get more examples and information than provided on the web page?_
+
+    Ideally a libxml2 book would be nice. I have no such plan ... But you can:
+    * check more deeply the [existing generated doc](http://xmlsoft.org/html/libxml-lib.html)
+    * have a look at [the set of examples](http://xmlsoft.org/examples/index.html).
+    * look for examples of use for libxml2 function using the Gnome code or by asking on Google.
+    * [Browse the libxml2 source](http://svn.gnome.org/viewvc/libxml2/trunk/) , I try to write code as clean 
and documented as possible, so looking at it may be helpful. In particular the code of 
[xmllint.c](http://svn.gnome.org/viewvc/libxml2/trunk/xmllint.c?view=markup) and of the various testXXX.c 
test programs should provide good 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 a number of platforms, including embedded 
systems. I don't intend to convert to C++.
+
+    There is however a C++ wrapper which may fulfill your needs:
+    * by Ari Johnson <[ari btigate com](mailto:ari btigate com)>:
+
+      Website: <https://libxmlplusplus.github.io/libxmlplusplus/>
+
+      Download: <https://download.gnome.org/sources/libxml++/>
+11. _How to validate a document a posteriori ?_
+
+    It is possible to validate documents which had not been validated at initial parsing time or documents 
which have been built from scratch using the API. Use the 
[xmlValidateDtd()](http://xmlsoft.org/html/libxml-valid.html#xmlValidateDtd) function. It is also possible to 
simply add a DTD to an existing document:
+
+    ```
+    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 only utf-8! You need to convert strings 
encoded in different ways to utf-8 before passing them to the API. This can be accomplished with the iconv 
library for instance.
\ No newline at end of file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]