diff --git a/expat/doc/reference.html b/expat/doc/reference.html index 0682a9e7..39116aa4 100644 --- a/expat/doc/reference.html +++ b/expat/doc/reference.html @@ -8,9 +8,9 @@ This is free software. You may distribute or modify according to the terms of the MIT/X License --> Expat XML Parser - - - + + +

Expat XML Parser

@@ -20,21 +20,21 @@ underlying XML parser for the open source Mozilla project, perl's XML::Parser, and other open-source XML parsers.

This library is the creation of James Clark, who's also given us -groff (an nroff look-alike), Jade (an implemention of ISO's DSSSL stylesheet -language for SGML), XP (a Java XML parser package), XT (a Java XSL engine). -James was also the technical lead on the XML Working Group at W3 that produced -the XML specification.

+groff (an nroff look-alike), Jade (an implemention of ISO's DSSSL +stylesheet language for SGML), XP (a Java XML parser package), XT (a +Java XSL engine). James was also the technical lead on the XML +Working Group at W3 that produced the XML specification.

-

This is free software, licensed under the -MIT/X Consortium license. You may download it from -the Expat home page. +

This is free software, licensed under the MIT/X Consortium license. You may download it +from the Expat home page.

The bulk of this document was originally commissioned as an article by -XML.com. They graciously allowed me to retain -copyright and to distribute it with expat. +XML.com. They graciously allowed +Clark Cooper to retain copyright and to distribute it with expat.

-
+

Table of Contents

-
+

Overview

-

Expat is a stream-oriented parser. You register callback (or handler) -functions with -the parser and then start feeding it the document. -As the parser recognizes parts of -the document, it will call the appropriate handler for that part (if you've -registered one.) The document is fed to the parser in pieces, so you can -start parsing before you have all the document. This also allows you to -parse really huge documents that won't fit into memory.

-

Expat can be intimidating due to the many kinds of handlers and options -you can set. But you only need to learn four functions in order to do 90% -of what you'll want to do with it:

+

Expat is a stream-oriented parser. You register callback (or +handler) functions with the parser and then start feeding it the +document. As the parser recognizes parts of the document, it will +call the appropriate handler for that part (if you've registered one.) +The document is fed to the parser in pieces, so you can start parsing +before you have all the document. This also allows you to parse really +huge documents that won't fit into memory.

+ +

Expat can be intimidating due to the many kinds of handlers and +options you can set. But you only need to learn four functions in +order to do 90% of what you'll want to do with it:

@@ -152,22 +152,22 @@ of what you'll want to do with it:

Pass a buffer full of document to the parser
-

These functions and others are described in the -reference part of this document. The reference -section also describes in detail the parameters passed to the different -types of handlers. +

These functions and others are described in the reference part of this document. The reference +section also describes in detail the parameters passed to the +different types of handlers.

-

Let's look at a very simple example program that only uses 3 of the above -functions (it doesn't need to set a character handler.) The program -outline.c -prints an element outline, indenting child elements to distinguish them from -the parent element that contains them. The start handler does all the work. -It prints two indenting spaces for every level of ancestor elements, then -it prints the element and attribute information. Finally it increments the -global Depth variable. +

Let's look at a very simple example program that only uses 3 of the +above functions (it doesn't need to set a character handler.) The +program outline.c prints an +element outline, indenting child elements to distinguish them from the +parent element that contains them. The start handler does all the +work. It prints two indenting spaces for every level of ancestor +elements, then it prints the element and attribute +information. Finally it increments the global Depth +variable.

-
-
+
 int Depth;
 
 void
@@ -187,45 +187,47 @@ start(void *data, const char *el, const char **attr) {
   Depth++;
 }  /* End of start handler */
 
-
-

The end tag simply does the bookkeeping work of decrementing the Depth. -

-
+

The end tag simply does the bookkeeping work of decrementing +Depth.

+
 void
 end(void *data, const char *el) {
   Depth--;
 }  /* End of end handler */
 
-

After creating the parser, the main program just has the job of -shoveling the document to the parser so that it can do its work. +shoveling the document to the parser so that it can do its work.

-
+

Building and Installing expat

-

The expat distribution comes as a compressed (with GNU gzip) tar file. -You may download the latest version from -Source Forge. -After unpacking this, cd into the directory. Then follow either the -Win32 directions or Unix directions below.

+ +

The expat distribution comes as a compressed (with GNU gzip) tar +file. You may download the latest version from Source Forge. After +unpacking this, cd into the directory. Then follow either the Win32 +directions or Unix directions below.

Building under Win32

-

If you're using the GNU compiler under cygwin, follow the Unix directions -in the next section. Otherwise if you have Microsoft's Developer Studio -installed, then from Windows Explorer double-click on "expat.dsp" in the -lib directory and build and install in the usual manner.

-

Alternatively, you may download the win32 binary package that contains -the expat.h include file and a pre-built dll.

+

If you're using the GNU compiler under cygwin, follow the Unix +directions in the next section. Otherwise if you have Microsoft's +Developer Studio installed, then from Windows Explorer double-click on +"expat.dsp" in the lib directory and build and install in the usual +manner.

+ +

Alternatively, you may download the Win32 binary package that +contains the expat.h include file and a pre-built DLL.

Building under Unix (or GNU)

-

First you'll need to run the configure shell script in order to configure -the Makefiles and headers for your system.

+ +

First you'll need to run the configure shell script in order to +configure the Makefiles and headers for your system.

If you're happy with all the defaults that configure picks for you, -and you have permission on your system to install into /usr/local, you can -install expat with this sequence of commands:

+and you have permission on your system to install into /usr/local, you +can install expat with this sequence of commands:

    ./configure
@@ -234,51 +236,48 @@ install expat with this sequence of commands:

There are some options that you can provide to this script, but the -only one we'll mention here is the --prefix option. You can -find out all the options available by running configure with just the ---help option. -

+only one we'll mention here is the --prefix option. You +can find out all the options available by running configure with just +the --help option.

-By default, the configure script sets things up so that the library gets -installed in /usr/local/lib and the associated header file in -/usr/local/include. -But if you were to give the option, --prefix=/home/me/mystuff, -then the library and header would get installed in -/home/me/mystuff/lib and /home/me/mystuff/include -respectively. -

+

By default, the configure script sets things up so that the library +gets installed in /usr/local/lib and the associated +header file in /usr/local/include. But if you were to +give the option, --prefix=/home/me/mystuff, then the +library and header would get installed in +/home/me/mystuff/lib and +/home/me/mystuff/include respectively.

-
+

Using Expat

-

Compiling and Linking against expat

-

Unless you installed expat in a location not expected by your compiler -and linker, all you have to do to use expat in your programs is to include -the expat header (#include <expat.h>) in your files that -make calls to it and to tell the linker -that it needs to link against the expat library. On Unix systems, this would -be the -lexpat argument. -Otherwise, you'll need to tell the compiler where to look for the expat header -and the linker where to find the expat library. You may also need to take -steps to tell the operating system where to find this libary at run time. -

-

On a Unix based system, here's what a Makefile might look like when expat -is installed in a standard location:

-
-
+

Compiling and Linking against expat

+ +

Unless you installed expat in a location not expected by your +compiler and linker, all you have to do to use expat in your programs +is to include the expat header (#include <expat.h>) +in your files that make calls to it and to tell the linker that it +needs to link against the expat library. On Unix systems, this would +be the -lexpat argument. Otherwise, you'll need to tell +the compiler where to look for the expat header and the linker where +to find the expat library. You may also need to take steps to tell the +operating system where to find this libary at run time.

+ +

On a Unix-based system, here's what a Makefile might look like when +expat is installed in a standard location:

+ +
 CC=cc
 LDFLAGS=
 LIBS= -lexpat
 xmlapp: xmlapp.o
         $(CC) $(LDFLAGS) -o xmlapp xmlapp.o $(LIBS)
 
-

If you installed expat in, say, /home/me/mystuff, then the Makefile would look like this:

-
-
+
 CC=cc
 CFLAGS= -I/home/me/mystuff/include
 LDFLAGS=
@@ -286,62 +285,61 @@ LIBS= -L/home/me/mystuff/lib -lexpat
 xmlapp: xmlapp.o
         $(CC) $(LDFLAGS) -o xmlapp xmlapp.o $(LIBS)
 
-
-

You'd also have to set the environment variable LD_LIBRARY_PATH -to /home/me/mystuff/lib (or to -${LD_LIBRARY_PATH}:/home/me/mystuff/lib if LD_LIBRARY_PATH -already has some directories in it) in order to run your application. -

+

You'd also have to set the environment variable +LD_LIBRARY_PATH to /home/me/mystuff/lib (or +to ${LD_LIBRARY_PATH}:/home/me/mystuff/lib if +LD_LIBRARY_PATH already has some directories in it) in order to run +your application.

Expat Basics

-

As we saw in the example in the overview, the first step in parsing an -XML document with expat is to create a parser object. There are -three functions in the expat API for creating a -parser object. -However, only two of these -(XML_ParserCreate and -XML_ParserCreateNS) -can be used for constructing a parser for a top-level document. -The object returned by these functions is an opaque pointer -(i.e. expat.h declares it as void *) to data with further internal structure. -In order to free the memory associated with this object you must call -XML_ParserFree. Note that if -you have provided any user data that gets stored -in the parser, then your application is responsible for freeing it prior to -calling XML_ParserFree. -

+ +

As we saw in the example in the overview, the first step in parsing +an XML document with expat is to create a parser object. There are three functions in the expat API for creating a +parser object. However, only two of these (XML_ParserCreate and XML_ParserCreateNS) can be used for +constructing a parser for a top-level document. The object returned +by these functions is an opaque pointer (i.e. expat.h declares it as +void *) to data with further internal structure. In order to free the +memory associated with this object you must call XML_ParserFree. Note that if you have +provided any user data that gets stored in the +parser, then your application is responsible for freeing it prior to +calling XML_ParserFree.

The objects returned by the parser creation functions are good for -parsing only one XML document or external parsed entity. If your application -needs to parse many XML documents, then it needs to create a parser object -for each one. The best way to deal with this is to create a higher level -object that contains all the default initialization you want for your parser -objects. +parsing only one XML document or external parsed entity. If your +application needs to parse many XML documents, then it needs to create +a parser object for each one. The best way to deal with this is to +create a higher level object that contains all the default +initialization you want for your parser objects.

-

Walking through a document hierarchy with a stream oriented parser will -require a good stack mechanism in order to keep track of current context. -For instance, to answer the simple question, -"What element does this text belong to?" requires a stack, since the -parser may have descended into other elements that are children of the -current one and has encountered this text on the way out. +

Walking through a document hierarchy with a stream oriented parser +will require a good stack mechanism in order to keep track of current +context. For instance, to answer the simple question, "What element +does this text belong to?" requires a stack, since the parser may have +descended into other elements that are children of the current one and +has encountered this text on the way out.

-

The things you're likely to want to keep on a stack are the currently -opened element and it's attributes. You push this information onto the -stack in the start handler and you pop it off in the end handler. +

The things you're likely to want to keep on a stack are the +currently opened element and it's attributes. You push this +information onto the stack in the start handler and you pop it off in +the end handler.

-

For some tasks, it is sufficient to just keep information on what the -depth of the stack is (or would be if you had one.) The outline program shown -above presents one example. Another such task would be skipping over a -complete element. When you see the start tag for the element you want to -skip, you set a skip flag and record the depth at which the element started. -When the end tag handler encounters the same depth, the skipped element has -ended and the flag may be cleared. If you follow the convention that the -root element starts at 1, then you can use the same variable for skip flag -and skip depth. +

For some tasks, it is sufficient to just keep information on what +the depth of the stack is (or would be if you had one.) The outline +program shown above presents one example. Another such task would be +skipping over a complete element. When you see the start tag for the +element you want to skip, you set a skip flag and record the depth at +which the element started. When the end tag handler encounters the +same depth, the skipped element has ended and the flag may be +cleared. If you follow the convention that the root element starts at +1, then you can use the same variable for skip flag and skip +depth.

-
-
+
 void
 init_info(Parseinfo *info) {
   info->skip = 0;
@@ -376,119 +374,118 @@ rawend(void *data, const char *el) {
   if (inf->skip == inf->depth)
     inf->skip = 0;
 }  /* End rawend */
-
 
-
-

Notice in the above example the difference in how depth is manipulated -in the start and end handlers. The end tag handler should be the mirror -image of the start tag handler. This is necessary to properly model -containment. Since, in the start tag handler, we -incremented depth after the main body of start tag code, then in -the end handler, we need to manipulate it before the main body. -If we'd decided to increment it first thing in the start handler, then -we'd have had to decrement it last thing in the end handler. +

Notice in the above example the difference in how depth is +manipulated in the start and end handlers. The end tag handler should +be the mirror image of the start tag handler. This is necessary to +properly model containment. Since, in the start tag handler, we +incremented depth after the main body of start tag code, then +in the end handler, we need to manipulate it before the main +body. If we'd decided to increment it first thing in the start +handler, then we'd have had to decrement it last thing in the end +handler.

Communicating between handlers

In order to be able to pass information between different handlers without using globals, you'll need to define a data structure to hold -the shared variables. You can then tell expat (with the XML_SetUserData -function) to pass a pointer to this -structure to the handlers. This is typically the first argument received -by most handlers. +the shared variables. You can then tell expat (with the XML_SetUserData function) to pass a +pointer to this structure to the handlers. This is typically the first +argument received by most handlers.

Namespace Processing

-

When the parser is created using the XML_ParserCreateNS, -function, expat performs namespace processing. Under namespace processing, -expat consumes xmlns and xmlns:... attributes, +

When the parser is created using the XML_ParserCreateNS, function, expat +performs namespace processing. Under namespace processing, expat +consumes xmlns and xmlns:... attributes, which declare namespaces for the scope of the element in which they -occur. This means that your start handler will not see these attributes. -Your application can still be informed of these declarations by setting -namespace declaration handlers with - -XML_SetNamespaceDeclHandler. +occur. This means that your start handler will not see these +attributes. Your application can still be informed of these +declarations by setting namespace declaration handlers with XML_SetNamespaceDeclHandler.

-

Element type and attribute names that belong to a given namespace are -passed to the appropriate handler in expanded form. By default this expanded -form is a concatenation of the namespace URI, the separator character (which -is the 2nd argument to XML_ParserCreateNS), and the local -name (i.e. the part after the colon). Names with undeclared prefixes are -passed through to the handlers unchanged, with the prefix and colon still -attached. Unprefixed attribute names are never expanded, and unprefixed -element names are only expanded when they are in the scope of a default -namespace. +

Element type and attribute names that belong to a given namespace +are passed to the appropriate handler in expanded form. By default +this expanded form is a concatenation of the namespace URI, the +separator character (which is the 2nd argument to XML_ParserCreateNS), and the local +name (i.e. the part after the colon). Names with undeclared prefixes +are passed through to the handlers unchanged, with the prefix and +colon still attached. Unprefixed attribute names are never expanded, +and unprefixed element names are only expanded when they are in the +scope of a default namespace.

-

However if XML_SetReturnNSTriplet -has been called with a non-zero do_nst parameter, then the -expanded form for names with an explicit prefix is a concatenation of: -URI, separator, local name, separator, prefix. -

+

However if XML_SetReturnNSTriplet has been called with a non-zero +do_nst parameter, then the expanded form for names with +an explicit prefix is a concatenation of: URI, separator, local name, +separator, prefix.

-

You can set handlers for the start of a namespace declaration and for -the end of a scope of a declaration with the -XML_SetNamespaceDeclHandler function. -The StartNamespaceDeclHandler is called prior to the start tag handler -and the EndNamespaceDeclHandler is called before the corresponding end tag -that ends the namespace's scope. -The namespace start handler gets passed the prefix and URI for the namespace. -For a default namespace declaration (xmlns='...'), the prefix will be null. -The URI will be null for the case where the default namespace is being unset. -The namespace end handler just gets the prefix for the closing scope. +

You can set handlers for the start of a namespace declaration and +for the end of a scope of a declaration with the XML_SetNamespaceDeclHandler +function. The StartNamespaceDeclHandler is called prior to the start +tag handler and the EndNamespaceDeclHandler is called before the +corresponding end tag that ends the namespace's scope. The namespace +start handler gets passed the prefix and URI for the namespace. For a +default namespace declaration (xmlns='...'), the prefix will be null. +The URI will be null for the case where the default namespace is being +unset. The namespace end handler just gets the prefix for the closing +scope.

-

These handlers are called for each declaration. So if, for instance, a -start tag had three namespace declarations, then the StartNamespaceDeclHandler -would be called three times before the start tag handler is called, once for -each declaration. - -

The namespace.c example demonstrates the -use of these features. Like outline.c, it produces an outline, but -in addition it annotates when a namespace scope starts and when it ends. -This example also demonstrates use of application user data. +

These handlers are called for each declaration. So if, for +instance, a start tag had three namespace declarations, then the +StartNamespaceDeclHandler would be called three times before the start +tag handler is called, once for each declaration.

Character Encodings

-

While XML is based on Unicode, and every XML processor is required to -recognized UTF-8 and UTF-16 (1 and 2 byte encodings of Unicode), other -encodings may be declared in XML documents or entities. For the main -document, an XML declaration may contain an encoding declaration: +

While XML is based on Unicode, and every XML processor is required +to recognized UTF-8 and UTF-16 (1 and 2 byte encodings of Unicode), +other encodings may be declared in XML documents or entities. For the +main document, an XML declaration may contain an encoding +declaration:

 <?xml version="1.0" encoding="ISO-8859-2"?>
 

External parsed entities may begin with a text declaration, which -looks like an XML declaration with just an encoding declaration: +looks like an XML declaration with just an encoding declaration:

 <?xml encoding="Big5"?>
 
-

With expat, you may also specify an encoding at the time of creating a -parser. This is useful when the encoding information may come from a source -outside the document itself (like a higher level protocol.) +

With expat, you may also specify an encoding at the time of +creating a parser. This is useful when the encoding information may +come from a source outside the document itself (like a higher level +protocol.)

-

There are four built-in encodings in expat: +

There are four built-in encodings +in expat:

Anything else discovered in an encoding declaration or in the protocol encoding specified in the parser constructor, triggers a call to the UnknownEncodingHandler. This handler gets passed the encoding name and a pointer to an XML_Encoding data -structure. Your handler must fill in this structure and return 1 if -it knows how to deal with the encoding. Otherwise the handler should -return 0. -The handler also gets passed a pointer to an -optional application data structure that you may indicate when you set -the handler. +structure. Your handler must fill in this structure and return 1 if it +knows how to deal with the encoding. Otherwise the handler should +return 0. The handler also gets passed a pointer to an optional +application data structure that you may indicate when you set the +handler.

-

Expat places restrictions on character encodings that it can support -by filling in the XML_Encoding structure. -include file: +

Expat places restrictions on character encodings that it can +support by filling in the XML_Encoding structure. +include file:

  1. Every ASCII character that can appear in a well-formed XML document must be represented by a single byte, and that byte must correspond to @@ -501,44 +498,48 @@ for UTF-16 and UTF-8
  2. bytes
-

XML_Encoding contains an array of integers that correspond -to the 1st byte of an encoding sequence. If the value in the array for a -byte is zero or positive, then the byte is a single byte encoding that -encodes the Unicode scalar value contained in the array. A -1 in this array -indicates a malformed byte. If the value is --2, -3, or -4, then the byte is the beginning of a 2, 3, or 4 byte sequence -respectively. Multi-byte sequences are sent to the convert function pointed -at in the XML_Encoding structure. This function should return -the Unicode scalar value for the sequence or -1 if the sequence is malformed. +

XML_Encoding contains an array of integers that +correspond to the 1st byte of an encoding sequence. If the value in +the array for a byte is zero or positive, then the byte is a single +byte encoding that encodes the Unicode scalar value contained in the +array. A -1 in this array indicates a malformed byte. If the value is +-2, -3, or -4, then the byte is the beginning of a 2, 3, or 4 byte +sequence respectively. Multi-byte sequences are sent to the convert +function pointed at in the XML_Encoding structure. This +function should return the Unicode scalar value for the sequence or -1 +if the sequence is malformed.

One pitfall that novice expat users are likely to fall into is that -although expat may accept input in various encodings, the strings that it -passes to the handlers are always encoded in UTF-8. Your application is -responsible for any translation of these strings into other encodings. +although expat may accept input in various encodings, the strings that +it passes to the handlers are always encoded in UTF-8. Your +application is responsible for any translation of these strings into +other encodings.

Handling External Entity References

-

Expat does not read or parse external entities directly. Note that any -external DTD is a special case of an external entity. -If you've set no ExternalEntityRefHandler, then external -entity references are silently ignored. Otherwise, it calls your handler with -the information needed to read and parse the external entity. +

Expat does not read or parse external entities directly. Note that +any external DTD is a special case of an external entity. If you've +set no ExternalEntityRefHandler, then external entity +references are silently ignored. Otherwise, it calls your handler with +the information needed to read and parse the external entity.

-

Your handler -isn't actually responsible for parsing the entity, but it is responsible -for creating a subsidiary parser with -XML_ExternalEntityParserCreate that will do the job. This returns -an instance of XML_Parser that has handlers and other data -structures initialized from the parent parser. You may then use -XML_Parse or XML_ParseBuffer calls against this -parser. -Since external entities my refer to other external entities, your handler -should be prepared to be called recursively. +

Your handler isn't actually responsible for parsing the entity, but +it is responsible for creating a subsidiary parser with XML_ExternalEntityParserCreate that will do the job. This +returns an instance of XML_Parser that has handlers and +other data structures initialized from the parent parser. You may then +use XML_Parse or XML_ParseBuffer calls against this +parser. Since external entities my refer to other external entities, +your handler should be prepared to be called recursively.

Parsing DTDs

-

In order to parse parameter entities, before starting the parse, you must -call XML_SetParamEntityParsing with one of the following -arguments: + +

In order to parse parameter entities, before starting the parse, +you must call XML_SetParamEntityParsing with one of the following +arguments:

XML_PARAM_ENTITY_PARSING_NEVER
Don't parse parameter entities or the external subset
@@ -549,13 +550,10 @@ arguments:
Always parse parameter entities and the external subset
-

In order to read an external DTD, you also have to set an -external entity reference handler as described above. +

In order to read an external DTD, you also have to set an external +entity reference handler as described above.

-
-

Some expat Examples

- -
+

Expat Reference

@@ -571,10 +569,10 @@ Construct a new parser. If encoding is non-null, it specifies a character encoding to use for the document. This overrides the document encoding declaration. There are four built-in encodings: Any other value will invoke a call to the UnknownEncodingHandler. @@ -604,13 +602,13 @@ standard set of memory management functions. If sep is non NULL, then namespace processing is enabled in the created parser and the character pointed at by sep is used as the separator between the namespace URI and the local part of the name

-
+
 typedef struct {
   void *(*malloc_fcn)(size_t size);
   void *(*realloc_fcn)(void *ptr, size_t size);
   void (*free_fcn)(void *ptr);
 } XML_Memory_Handling_Suite;
-
+
@@ -620,13 +618,13 @@ XML_ExternalEntityParserCreate(XML_Parser p,
                                const XML_Char *encoding)
 
-Construct a new XML_Parser object for parsing an external general -entity. Context is the context argument passed in a call to a -ExternalEntityRefHandler. Other state information such as handlers, user data, -namespace processing is inherited from the parser passed as the 1st -argument. So you shouldn't need to call any of the behavior changing -functions on this parser (unless you want it to act differently than the -parent parser.) +Construct a new XML_Parser object for parsing an external +general entity. Context is the context argument passed in a call to a +ExternalEntityRefHandler. Other state information such as handlers, +user data, namespace processing is inherited from the parser passed as +the 1st argument. So you shouldn't need to call any of the behavior +changing functions on this parser (unless you want it to act +differently than the parent parser.)
@@ -639,12 +637,17 @@ freeing any memory associated with UserData.
 

Parsing

-

To state the obvious: the three parsing functions XML_Parse, -XML_ParseBuffer and XML_GetBuffer must not be called -from within a handler unless they operate on a separate parser instance, that is, -one that did not call the handler. For example, it is OK to call the parsing -functions from within an XML_ExternalEntityRefHandler, if they -apply to the parser created by XML_ExternalEntityParserCreate.

+ +

To state the obvious: the three parsing functions XML_Parse, XML_ParseBuffer and >XML_GetBuffer must not be +called from within a handler unless they operate on a separate parser +instance, that is, one that did not call the handler. For example, it +is OK to call the parsing functions from within an +XML_ExternalEntityRefHandler, if they apply to the parser +created by XML_ExternalEntityParserCreate.

 XML_Status
@@ -697,8 +700,7 @@ into. A NULL value is returned if expat can't allocate enough memory for
 this buffer. This has to be called prior to every call to
 XML_ParseBuffer. A typical use would look like this:
 
-
-
+
 for (;;) {
   int bytes_read;
   void *buff = XML_GetBuffer(p, BUFF_SIZE);
@@ -707,7 +709,7 @@ for (;;) {
   }
 
   bytes_read = read(docfd, buff, BUFF_SIZE);
-  if (bytes_read < 0) {
+  if (bytes_read < 0) {
     /* handle error */
   }
 
@@ -717,10 +719,9 @@ for (;;) {
 
   if (bytes_read == 0)
     break;
-}  
+}
 
-

Handler Setting

Although handlers are typically set prior to parsing and left alone, an @@ -728,17 +729,17 @@ application may choose to set or change the handler for a parsing event while the parse is in progress. For instance, your application may choose to ignore all text not descended from a para element. One way it could do this is to set the character handler when a para start tag -is seen, and unset it for the corresponding end tag. +is seen, and unset it for the corresponding end tag.

A handler may be unset by providing a NULL pointer to the appropriate handler setter. None of the handler setting functions have -a return value. +a return value.

Your handlers will be receiving strings in arrays of type -XML_Char. This type is defined in expat.h as char * -and contains bytes encoding UTF-8. -Note that you'll receive them in this form independent of the original -encoding of the document.

+XML_Char. This type is defined in expat.h as char +* and contains bytes encoding UTF-8. Note that you'll receive +them in this form independent of the original encoding of the +document.

@@ -971,16 +972,16 @@ typedef void
 

Set a skipped entity handler. This is called in two situations:

  1. An entity reference is encountered for which no declaration - has been read *and* this is not an error.
  2. + has been read and this is not an error.
  3. An internal entity reference is read, but not expanded, because XML_SetDefaultHandler has been called.

The is_parameter_entity argument will be non-zero for -a parameter entity and zero for a general entity.

-

Note: skipped parameter entities in declarations and skipped general -entities in attribute values cannot be reported, because the event would -be out of sync with the reporting of the declarations or attribute values

+a parameter entity and zero for a general entity.

Note: skipped +parameter entities in declarations and skipped general entities in +attribute values cannot be reported, because the event would be out of +sync with the reporting of the declarations or attribute values

@@ -1053,9 +1054,9 @@ typedef void const XML_Char *prefix);

Set a handler to be called when leaving the scope of a namespace -declaration. This will be called, for each namespace declaration, after -the handler for the end tag of the element in which the namespace was declared. -

+declaration. This will be called, for each namespace declaration, +after the handler for the end tag of the element in which the +namespace was declared.

@@ -1080,12 +1081,13 @@ typedef void int standalone);

Sets a handler that is called for XML declarations and also for -text declarations discovered in external entities. The way to distinguish -is that the version parameter will be NULL for text -declarations. The encoding parameter may be NULL for -an XML declaration. The standalone argument will contain --1, 0, or 1 indicating respectively that there was no standalone parameter in -the declaration, that it was given as no, or that it was given as yes.

+text declarations discovered in external entities. The way to +distinguish is that the version parameter will be NULL +for text declarations. The encoding parameter may be NULL +for an XML declaration. The standalone argument will +contain -1, 0, or 1 indicating respectively that there was no +standalone parameter in the declaration, that it was given as no, or +that it was given as yes.

@@ -1167,33 +1169,35 @@ struct XML_cp { XML_Content * children; };
-

Sets a handler for element declarations in a DTD. The handler gets called -with the name of the element in the declaration and a pointer to a structure -that contains the element model. It is the application's responsibility to -free this data structure.

+

Sets a handler for element declarations in a DTD. The handler gets +called with the name of the element in the declaration and a pointer +to a structure that contains the element model. It is the +application's responsibility to free this data structure.

The model argument is the root of a tree of XML_Content nodes. If type equals XML_CTYPE_EMPTY or XML_CTYPE_ANY, then -quant will be XML_CQUANT_NONE, and the other fields -will be zero or NULL. -If type is XML_CTYPE_MIXED, then quant -will be XML_CQUANT_NONE or XML_CQUANT_REP and -numchildren will contain the number of elements that are allowed -to be mixed in and children points to an array of -XML_Content structures that will all have type XML_CTYPE_NAME -with no quantification. -Only the root node can be type XML_CTYPE_EMPTY, XML_CTYPE_ANY, or XML_CTYPE_MIXED.

+quant will be XML_CQUANT_NONE, and the other +fields will be zero or NULL. If type is +XML_CTYPE_MIXED, then quant will be +XML_CQUANT_NONE or XML_CQUANT_REP and +numchildren will contain the number of elements that are +allowed to be mixed in and children points to an array of +XML_Content structures that will all have type +XML_CTYPE_NAME with no quantification. Only the root node can be type +XML_CTYPE_EMPTY, XML_CTYPE_ANY, or +XML_CTYPE_MIXED.

-

For type XML_CTYPE_NAME, the name field points -to the name and the numchildren and children fields -will be zero and NULL. The quant field will indicate any -quantifiers placed on the name.

+

For type XML_CTYPE_NAME, the name field +points to the name and the numchildren and +children fields will be zero and NULL. The +quant field will indicate any quantifiers placed on the +name.

Types XML_CTYPE_CHOICE and XML_CTYPE_SEQ -indicate a choice or sequence respectively. The numchildren -field indicates how many nodes in the choice or sequence and -children points to the nodes.

+indicate a choice or sequence respectively. The +numchildren field indicates how many nodes in the choice +or sequence and children points to the nodes.

@@ -1210,23 +1214,22 @@ typedef void const XML_Char *dflt, int isrequired);
-

Set a handler for attlist declarations in the DTD. This handler is called -for each attribute. So a single attlist declaration with multiple -attributes declared will generate multiple calls to this handler. The -elname parameter returns the name of the element for which the -attribute is being declared. The attribute name is in the attname -parameter. The attribute type is in the att_type parameter. -It is the string representing the type in the declaration with whitespace -removed.

+

Set a handler for attlist declarations in the DTD. This handler is +called for each attribute. So a single attlist declaration +with multiple attributes declared will generate multiple calls to this +handler. The elname parameter returns the name of the +element for which the attribute is being declared. The attribute name +is in the attname parameter. The attribute type is in the +att_type parameter. It is the string representing the +type in the declaration with whitespace removed.

-

The dflt parameter holds the default value. It will -be NULL in the case of "#IMPLIED" or "#REQUIRED" attributes. You can +

The dflt parameter holds the default value. It will be +NULL in the case of "#IMPLIED" or "#REQUIRED" attributes. You can distinguish these two cases by checking the isrequired parameter, which will be true in the case of "#REQUIRED" attributes. Attributes which are "#FIXED" will have also have a true -isrequired, but they will have the non-NULL fixed value in the -dflt parameter. -

+isrequired, but they will have the non-NULL fixed value +in the dflt parameter.

@@ -1247,18 +1250,19 @@ typedef void const XML_Char *notationName);

Sets a handler that will be called for all entity declarations. -The is_parameter_entity argument will be non-zero in the case -of parameter entities and zero otherwise. -

+The is_parameter_entity argument will be non-zero in the +case of parameter entities and zero otherwise.

+

For internal entities (<!ENTITY foo "bar">), value will be non-NULL and systemId, publicId, and notationName will all be NULL. -The value string is not NULL terminated; the length is provided in -the value_length parameter. Do not use value_length -to test for internal entities, since it is legal to have zero-length -values. Instead check for whether or not value is NULL.

-

The notationName argument will have a non-NULL value only -for unparsed entity declarations.

+The value string is not NULL terminated; the length is +provided in the value_length parameter. Do not use +value_length to test for internal entities, since it is +legal to have zero-length values. Instead check for whether or not +value is NULL.

The notationName +argument will have a non-NULL value only for unparsed entity +declarations.

@@ -1281,10 +1285,9 @@ are entity declarations that have a notation (NDATA) field:

 <!ENTITY logo SYSTEM "images/logo.gif" NDATA gif>
 
- -

This handler is obsolete and is provided for backwards compatibility. -Use instead XML_SetEntityDeclHandler. -

+

This handler is obsolete and is provided for backwards +compatibility. Use instead XML_SetEntityDeclHandler.

@@ -1313,22 +1316,25 @@ typedef int (*XML_NotStandaloneHandler)(void *userData);

Set a handler that is called if the document is not "standalone". -This happens when there is an external subset or a reference to a parameter -entity, but does not have standalone set to "yes" in an XML declaration. -If this handler returns 0, then the parser will throw an +This happens when there is an external subset or a reference to a +parameter entity, but does not have standalone set to "yes" in an XML +declaration. If this handler returns 0, then the parser will throw an XML_ERROR_NOT_STANDALONE error.

Parse position and error reporting functions

-

These are the functions you'll want to call when the parse functions -return 0 (i.e. a parse error has ocurred), although the position reporting -functions are useful outside of errors. The position reported is the byte -position (in the original document or entity encoding) of the first of the -sequence of characters that generated the current event (or the error that -caused the parse functions to return 0.)

-

The position reporting functions are accurate only outside of the DTD. -In other words, they usually return bogus information when called from within -a DTD declaration handler.

+ +

These are the functions you'll want to call when the parse +functions return 0 (i.e. a parse error has ocurred), although the +position reporting functions are useful outside of errors. The +position reported is the byte position (in the original document or +entity encoding) of the first of the sequence of characters that +generated the current event (or the error that caused the parse +functions to return 0.)

+ +

The position reporting functions are accurate only outside of the +DTD. In other words, they usually return bogus information when +called from within a DTD declaration handler.

 enum XML_Error
@@ -1392,22 +1398,26 @@ XML_GetInputContext(XML_Parser p,
                     int *size);
 
+

Returns the parser's input buffer, sets the integer pointed at by offset to the offset within this buffer of the current -parse position, and set the integer pointed at by size -to the size of the returned buffer.

+parse position, and set the integer pointed at by size to +the size of the returned buffer.

+

This should only be called from within a handler during an active parse and the returned buffer should only be referred to from within -the handler that made the call. This input buffer contains the untranslated -bytes of the input.

-

Only a limited amount of context is kept, so if the event triggering -a call spans over a very large amount of input, the actual parse position -may be before the beginning of the buffer.

+the handler that made the call. This input buffer contains the +untranslated bytes of the input.

+ +

Only a limited amount of context is kept, so if the event +triggering a call spans over a very large amount of input, the actual +parse position may be before the beginning of the buffer.

Miscellaneous functions

-

The functions in this section either obtain state information from the -parser or can be used to dynamicly set parser options. + +

The functions in this section either obtain state information from +the parser or can be used to dynamicly set parser options.

 void
@@ -1415,12 +1425,12 @@ XML_SetUserData(XML_Parser p,
                 void *userData)
 
-This sets the user data pointer that gets passed to handlers. -It overwrites any previous value for this pointer. Note that the +This sets the user data pointer that gets passed to handlers. It +overwrites any previous value for this pointer. Note that the application is responsible for freeing the memory associated with -userData when it is finished with the parser. So if -you call this when there's already a pointer there, and you haven't -freed the memory associated with it, then you've probably just leaked +userData when it is finished with the parser. So if you +call this when there's already a pointer there, and you haven't freed +the memory associated with it, then you've probably just leaked memory.
@@ -1449,9 +1459,9 @@ XML_SetBase(XML_Parser p, const XML_Char *base)
-Set the base to be used for resolving relative URIs in system identifiers. -The return value is 0 if there's no memory to store base, otherwise it's -non-zero. +Set the base to be used for resolving relative URIs in system +identifiers. The return value is 0 if there's no memory to store +base, otherwise it's non-zero.
@@ -1470,11 +1480,12 @@ XML_GetSpecifiedAttributeCount(XML_Parser p)
 When attributes are reported to the start handler in the atts vector,
 attributes that were explicitly set in the element occur before any
 attributes that receive their value from default information in an
-ATTLIST declaration. This function returns the number of attributes that
-were explicitly set times two, thus giving the offset in the atts
-array passed to the start tag handler of the first attribute set
-due to defaults. It supplies information for the last call to a start
-handler. If called inside a start handler, then that means the current call.
+ATTLIST declaration. This function returns the number of attributes
+that were explicitly set times two, thus giving the offset in the
+atts array passed to the start tag handler of the first
+attribute set due to defaults. It supplies information for the last
+call to a start handler. If called inside a start handler, then that
+means the current call.
 
@@ -1482,9 +1493,10 @@ int
 XML_GetIdAttributeIndex(XML_Parser p);
 
-Returns the index of the ID attribute passed in the atts array -in the last call to XML_StartElementHandler, or -1 if there is no ID -attribute. If called inside a start handler, then that means the current call. +Returns the index of the ID attribute passed in the atts array in the +last call to XML_StartElementHandler, or -1 if there is no ID +attribute. If called inside a start handler, then that means the +current call.
@@ -1495,8 +1507,9 @@ XML_SetEncoding(XML_Parser p,
 
 
 
@@ -1524,16 +1537,18 @@ XML_SetReturnNSTriplet(XML_Parser parser,
 

This function only has an effect when using a parser created with -XML_ParserCreateNS, i.e. when namespace -processing is in effect. The do_nst sets whether or not prefixes -are returned with names qualified with a namespace prefix. If this function -is called with do_nst non-zero, then afterwards namespace -qualified names (that is qualified with a prefix as opposed to belonging -to a default namespace) are returned as a triplet with the three parts -separated by the namespace separator specified when the parser was created. -The order of returned parts is URI, local name, and prefix.

-

If do_nst is zero, then namespaces are reported in the -default manner, URI then local_name separated by the namespace separator.

+XML_ParserCreateNS, +i.e. when namespace processing is in effect. The do_nst +sets whether or not prefixes are returned with names qualified with a +namespace prefix. If this function is called with do_nst +non-zero, then afterwards namespace qualified names (that is qualified +with a prefix as opposed to belonging to a default namespace) are +returned as a triplet with the three parts separated by the namespace +separator specified when the parser was created. The order of +returned parts is URI, local name, and prefix.

If +do_nst is zero, then namespaces are reported in the +default manner, URI then local_name separated by the namespace +separator.

Return the library version information as a structure. -
+
 typedef struct {
   int major;
   int minor;
   int micro;
 } XML_Expat_Version;
-
+
Some macros are also defined that support compile-time tests of the library version:
    @@ -1581,7 +1596,6 @@ library version: Testing these constants is currently the best way to determine if particular parts of the Expat API are available.
-