diff --git a/ChangeLog b/ChangeLog index d22e1ef2..05874b3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sat Oct 18 11:04:32 CEST 2003 Daniel Veillard + + * xmlreader.c include/libxml/xmlreader.h: added new APIs + for creating reader from sources or reusing a reader with + a new source, like the xmlReadxx and xmlCtxtReadxxx + * win32/libxml2.def.src doc/libxml2-api.xml doc/apibuild.py + doc/Makefile.am: regenerated the APIs + * doc/xml.html: applied a patch from Stefan Kost for namesapce docs + Sat Oct 18 12:46:02 HKT 2003 William Brack * genChRanges.py, chvalid.c, include/libxml/chvalid.h, diff --git a/doc/Makefile.am b/doc/Makefile.am index d018f397..7aef77d3 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -60,7 +60,7 @@ xmlcatalog.1: xmlcatalog_man.xml -@(xsltproc --nonet xmlcatalog_man.xml) scan: - -gtkdoc-scan --module=libxml --source-dir=$(DOC_SOURCE_DIR) --ignore-headers="acconfig.h config.h win32config.h trio.h triostr.h triop.h config-mac.h XMLTestPrefix2.h XMLTestPrefix.h triodef.h trionan.h xlink.h libxml.h libxml2-py.h libxml_wrap.h" + -gtkdoc-scan --module=libxml --source-dir=$(DOC_SOURCE_DIR) --ignore-headers="acconfig.h config.h win32config.h trio.h triostr.h triop.h config-mac.h XMLTestPrefix2.h XMLTestPrefix.h triodef.h trionan.h xlink.h libxml.h libxml2-py.h libxml_wrap.h chvalid.h" templates: scan -gtkdoc-mktmpl --module=libxml diff --git a/doc/apibuild.py b/doc/apibuild.py index 59cc0cf2..ce2f738c 100755 --- a/doc/apibuild.py +++ b/doc/apibuild.py @@ -25,6 +25,9 @@ ignored_files = { "testOOM.c": "out of memory tester", "testOOMlib.h": "out of memory tester", "testOOMlib.c": "out of memory tester", + "chvalid.h": "internal only + parsing problems", + "pattern.c": "not integrated yet", + "pattern.h": "not integrated yet", } ignored_words = { diff --git a/doc/libxml2-api.xml b/doc/libxml2-api.xml index 4cfee68b..1effbc0b 100644 --- a/doc/libxml2-api.xml +++ b/doc/libxml2-api.xml @@ -140,15 +140,7 @@ - - - - - - - - @@ -206,6 +198,7 @@ + @@ -1385,6 +1378,16 @@ + + + + + + + + + + @@ -4911,6 +4914,7 @@ actually an xmlCharEncoding'/> + @@ -8053,41 +8057,11 @@ actually an xmlCharEncoding'/> - - Check whether the character is allowed by the production [85] BaseChar ::= ... long list see REC ... VI is your friend ! :1,$ s/\[#x\([0-9A-Z]*\)-#x\([0-9A-Z]*\)\]/ (((c) >= 0x\1) \&\& ((c) <= 0x\2)) ||/ and :1,$ s/#x\([0-9A-Z]*\)/ ((c) == 0x\1) ||/ - - - - - Check whether the character is allowed by the production [3] S ::= (#x20 | #x9 | #xD | #xA)+ Also available as a macro IS_BLANK() - - - Checks whether this node is an empty or whitespace only (and possibly ignorable) text-node. - - Check whether the character is allowed by the production [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. Also available as a macro IS_CHAR() - - - - - Check whether the character is allowed by the production [87] CombiningChar ::= ... long list see REC ... - - - - - Check whether the character is allowed by the production [88] Digit ::= ... long list see REC ... - - - - - Check whether the character is allowed by the production [89] Extender ::= #x00B7 | #x02D0 | #x02D1 | #x0387 | #x0640 | #x0E46 | #x0EC6 | #x3005 | [#x3031-#x3035] | [#x309D-#x309E] | [#x30FC-#x30FE] - - - Determine whether an attribute is of type ID. In case we have DTD(s) then this is done if DTD loading has been requested. In the case of HTML documents parsed with the HTML parser, then ID detection is done systematically. @@ -8095,11 +8069,6 @@ actually an xmlCharEncoding'/> - - Check whether the character is allowed by the production [86] Ideographic ::= [#x4E00-#x9FA5] | #x3007 | [#x3021-#x3029] - - - Check whether the character is allowed by the production [84] Letter ::= BaseChar | Ideographic @@ -8115,11 +8084,6 @@ actually an xmlCharEncoding'/> - - Check whether the character is allowed by the production [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%] - - - Determine whether an attribute is of type Ref. In case we have DTD(s) then this is simple, otherwise we use an heuristic: name Ref (upper or lowercase). @@ -9700,6 +9664,95 @@ actually an xmlCharEncoding'/> + + Create an xmltextReader for an XML in-memory document. + + + + + + + + Create an xmltextReader for an XML from a file descriptor. + + + + + + + + parse an XML file from the filesystem or the network. + + + + + + + Create an xmltextReader for an XML document from I/O functions and source. + + + + + + + + + + Create an xmltextReader for an XML in-memory document. + + + + + + + + + Setup an xmltextReader to parse an XML in-memory document. This reuses the existing @reader xmlTextReader. + + + + + + + + + Setup an xmltextReader to parse an XML from a file descriptor. This reuses the existing @reader xmlTextReader. + + + + + + + + + parse an XML file from the filesystem or the network. This reuses the existing @reader xmlTextReader. + + + + + + + + Setup an xmltextReader to parse an XML document from I/O functions and source. This reuses the existing @reader xmlTextReader. + + + + + + + + + + + Setup an xmltextReader to parse an XML in-memory document. This reuses the existing @reader xmlTextReader. + + + + + + + + Signature for a realloc() implementation. diff --git a/doc/namespaces.html b/doc/namespaces.html index d50f10ba..6f15c5fd 100644 --- a/doc/namespaces.html +++ b/doc/namespaces.html @@ -34,12 +34,21 @@ same as <bar:text> in another document. What really matters is the URI associated with the element or the attribute, not the prefix string (which is just a shortcut for the full URI). In libxml, element and attributes have an ns field pointing to an xmlNs structure detailing the namespace -prefix and its URI.

@@Interfaces@@

@@Examples@@

Usually people object to using namespaces together with validity checking. +prefix and its URI.

@@Interfaces@@

+xmlNodePtr node;
+if(!strncmp(node->name,"mytag",5)
+  && node->ns
+  && !strcmp(node->ns->href,"http://www.mysite.com/myns/1.0")) {
+  ...
+}
+

Usually people object to using namespaces together with validity checking. I will try to make sure that using namespaces won't break validity checking, so even if you plan to use or currently are using validation I strongly suggest adding namespaces to your document. A default namespace scheme xmlns="http://...." should not break validity even on less flexible parsers. Using namespaces to mix and differentiate content coming -from multiple DTDs will certainly break current validation schemes. I will -try to provide ways to do this, but this may not be portable or -standardized.

Daniel Veillard

+from multiple DTDs will certainly break current validation schemes. +To check such documents one needs to use schema-validation, which is supported +in libxml2 as well. See relagx-ng and +w3c-schema. +

Daniel Veillard

diff --git a/doc/upgrade.html b/doc/upgrade.html index 335e9bc2..8196a483 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -23,7 +23,7 @@ incompatible changes. The main goals were:

  • a general cleanup. A numbe

How to fix libxml-1.x code:

So client code of libxml designed to run with version 1.x may have to be changed to compile against version 2.x of libxml. Here is a list of changes that I have collected, they may not be sufficient, so in case you find other -change which are required, drop me a +change which are required, drop me a mail:

  1. The package name have changed from libxml to libxml2, the library name is now -lxml2 . There is a new xml2-config script which should be used to select the right parameters libxml2
  2. diff --git a/doc/xml.html b/doc/xml.html index d72d4b99..f7fcdaaf 100644 --- a/doc/xml.html +++ b/doc/xml.html @@ -3758,7 +3758,14 @@ prefix and its URI.

    @@Interfaces@@

    -

    @@Examples@@

    +
    +xmlNodePtr node;
    +if(!strncmp(node->name,"mytag",5)
    +  && node->ns
    +  && !strcmp(node->ns->href,"http://www.mysite.com/myns/1.0")) {
    +  ...
    +}
    +

    Usually people object to using namespaces together with validity checking. I will try to make sure that using namespaces won't break validity checking, @@ -3766,9 +3773,11 @@ so even if you plan to use or currently are using validation I strongly suggest adding namespaces to your document. A default namespace scheme xmlns="http://...." should not break validity even on less flexible parsers. Using namespaces to mix and differentiate content coming -from multiple DTDs will certainly break current validation schemes. I will -try to provide ways to do this, but this may not be portable or -standardized.

    +from multiple DTDs will certainly break current validation schemes. +To check such documents one needs to use schema-validation, which is supported +in libxml2 as well. See relagx-ng and +w3c-schema. +

    Upgrading 1.x code

    @@ -3796,7 +3805,7 @@ incompatible changes. The main goals were:

    So client code of libxml designed to run with version 1.x may have to be changed to compile against version 2.x of libxml. Here is a list of changes that I have collected, they may not be sufficient, so in case you find other -change which are required, drop me a +change which are required, drop me a mail:

    1. The package name have changed from libxml to libxml2, the library name diff --git a/include/libxml/xmlreader.h b/include/libxml/xmlreader.h index 67c625e0..bbff65d6 100644 --- a/include/libxml/xmlreader.h +++ b/include/libxml/xmlreader.h @@ -205,6 +205,69 @@ XMLPUBFUN int XMLCALL xmlRelaxNGPtr schema); #endif +/* + * New more complete APIs for simpler creation and reuse of readers + */ +XMLPUBFUN xmlTextReaderPtr XMLCALL + xmlReaderForDoc (const xmlChar * cur, + const char *URL, + const char *encoding, + int options); +XMLPUBFUN xmlTextReaderPtr XMLCALL + xmlReaderForFile (const char *filename, + const char *encoding, + int options); +XMLPUBFUN xmlTextReaderPtr XMLCALL + xmlReaderForMemory (const char *buffer, + int size, + const char *URL, + const char *encoding, + int options); +XMLPUBFUN xmlTextReaderPtr XMLCALL + xmlReaderForFd (int fd, + const char *URL, + const char *encoding, + int options); +XMLPUBFUN xmlTextReaderPtr XMLCALL + xmlReaderForIO (xmlInputReadCallback ioread, + xmlInputCloseCallback ioclose, + void *ioctx, + const char *URL, + const char *encoding, + int options); + +XMLPUBFUN int XMLCALL + xmlReaderNewDoc (xmlTextReaderPtr reader, + const xmlChar * cur, + const char *URL, + const char *encoding, + int options); +XMLPUBFUN int XMLCALL + xmlReaderNewFile (xmlTextReaderPtr reader, + const char *filename, + const char *encoding, + int options); +XMLPUBFUN int XMLCALL + xmlReaderNewMemory (xmlTextReaderPtr reader, + const char *buffer, + int size, + const char *URL, + const char *encoding, + int options); +XMLPUBFUN int XMLCALL + xmlReaderNewFd (xmlTextReaderPtr reader, + int fd, + const char *URL, + const char *encoding, + int options); +XMLPUBFUN int XMLCALL + xmlReaderNewIO (xmlTextReaderPtr reader, + xmlInputReadCallback ioread, + xmlInputCloseCallback ioclose, + void *ioctx, + const char *URL, + const char *encoding, + int options); /* * Error handling extensions */ diff --git a/python/libxml2class.txt b/python/libxml2class.txt index 2f37fb31..f5cbc7e1 100644 --- a/python/libxml2class.txt +++ b/python/libxml2class.txt @@ -133,15 +133,7 @@ createFileParserCtxt() createMemoryParserCtxt() htmlCreateFileParserCtxt() htmlInitAutoClose() -isBaseChar() -isBlank() -isChar() -isCombining() -isDigit() -isExtender() -isIdeographic() isLetter() -isPubidChar() namePop() namePush() nodePop() @@ -213,6 +205,10 @@ resetLastError() # functions from module xmlreader newTextReaderFilename() +readerForDoc() +readerForFd() +readerForFile() +readerForMemory() # functions from module xmlregexp regexpCompile() @@ -709,6 +705,10 @@ Class xmlTextReader(xmlTextReaderCore) SetParserProp() Value() XmlLang() + readerNewDoc() + readerNewFd() + readerNewFile() + readerNewMemory() Class xmlReg() # functions from module xmlregexp diff --git a/win32/libxml2.def.src b/win32/libxml2.def.src index 3864d9a1..2aea070b 100644 --- a/win32/libxml2.def.src +++ b/win32/libxml2.def.src @@ -85,6 +85,7 @@ __xmlKeepBlanksDefaultValue #else xmlKeepBlanksDefaultValue DATA #endif +xmlLastError DATA #ifdef LIBXML_THREAD_ENABLED __xmlLineNumbersDefaultValue #else @@ -115,6 +116,7 @@ __xmlParserDebugEntities #else xmlParserDebugEntities DATA #endif +xmlParserMaxDepth DATA #ifdef LIBXML_THREAD_ENABLED __xmlParserVersion #else @@ -143,6 +145,7 @@ xmlSaveNoEmptyTags DATA xmlStringComment DATA xmlStringText DATA xmlStringTextNoenc DATA +xmlStructuredError DATA #ifdef LIBXML_THREAD_ENABLED __xmlSubstituteEntitiesDefaultValue #else @@ -644,6 +647,7 @@ xmlCopyElementContent xmlCopyElementTable xmlCopyEntitiesTable xmlCopyEnumeration +xmlCopyError xmlCopyNamespace xmlCopyNamespaceList xmlCopyNode @@ -661,12 +665,14 @@ xmlCreateIntSubset xmlCreateMemoryParserCtxt xmlCreatePushParserCtxt xmlCreateURI +xmlCtxtGetLastError xmlCtxtReadDoc xmlCtxtReadFd xmlCtxtReadFile xmlCtxtReadIO xmlCtxtReadMemory xmlCtxtReset +xmlCtxtResetLastError xmlCtxtUseOptions xmlCurrentChar #ifdef LIBXML_DEBUG_ENABLED @@ -720,6 +726,33 @@ xmlDocDumpMemoryEnc xmlDocFormatDump xmlDocGetRootElement xmlDocSetRootElement +xmlDocWalkerAttributeCount +xmlDocWalkerBaseUri +xmlDocWalkerCurrentDoc +xmlDocWalkerCurrentNode +xmlDocWalkerDepth +xmlDocWalkerGetAttribute +xmlDocWalkerGetAttributeNo +xmlDocWalkerGetAttributeNs +xmlDocWalkerHasAttributes +xmlDocWalkerHasValue +xmlDocWalkerIsEmptyElement +xmlDocWalkerLocalName +xmlDocWalkerLookupNamespace +xmlDocWalkerMoveToAttribute +xmlDocWalkerMoveToAttributeNo +xmlDocWalkerMoveToAttributeNs +xmlDocWalkerMoveToElement +xmlDocWalkerMoveToFirstAttribute +xmlDocWalkerMoveToNextAttribute +xmlDocWalkerName +xmlDocWalkerNamespaceUri +xmlDocWalkerNext +xmlDocWalkerNodeType +xmlDocWalkerPrefix +xmlDocWalkerRewind +xmlDocWalkerStep +xmlDocWalkerValue xmlDumpAttributeDecl xmlDumpAttributeTable xmlDumpElementDecl @@ -732,6 +765,7 @@ xmlElemDump xmlEncodeEntities xmlEncodeEntitiesReentrant xmlEncodeSpecialChars +xmlErrMemory xmlFileClose xmlFileMatch xmlFileOpen @@ -745,6 +779,7 @@ xmlFreeAutomata xmlFreeCatalog #endif xmlFreeDoc +xmlFreeDocWalker xmlFreeDtd xmlFreeElementContent xmlFreeElementTable @@ -789,6 +824,7 @@ xmlGetGlobalState xmlGetID xmlGetIntSubset xmlGetLastChild +xmlGetLastError xmlGetLineNo xmlGetNoNsProp xmlGetNodePath @@ -866,19 +902,11 @@ xmlInitializeCatalog #endif xmlInitializeGlobalState xmlInitializePredefinedEntities -xmlIsBaseChar -xmlIsBlank xmlIsBlankNode -xmlIsChar -xmlIsCombining -xmlIsDigit -xmlIsExtender xmlIsID -xmlIsIdeographic xmlIsLetter xmlIsMainThread xmlIsMixedElement -xmlIsPubidChar xmlIsRef #ifdef LIBXML_HTML_ENABLED xmlIsXHTML @@ -1080,6 +1108,7 @@ xmlNewDocProp xmlNewDocRawNode xmlNewDocText xmlNewDocTextLen +xmlNewDocWalker xmlNewDtd xmlNewElementContent xmlNewEntityInputStream @@ -1233,6 +1262,16 @@ xmlReadFd xmlReadFile xmlReadIO xmlReadMemory +xmlReaderForDoc +xmlReaderForFd +xmlReaderForFile +xmlReaderForIO +xmlReaderForMemory +xmlReaderNewDoc +xmlReaderNewFd +xmlReaderNewFile +xmlReaderNewIO +xmlReaderNewMemory #ifdef DEBUG_MEMORY_LOCATION xmlReallocLoc #endif @@ -1340,6 +1379,8 @@ xmlRemoveID xmlRemoveProp xmlRemoveRef xmlReplaceNode +xmlResetError +xmlResetLastError xmlSAX2AttributeDecl xmlSAX2CDataBlock xmlSAX2Characters @@ -1480,6 +1521,7 @@ xmlSetListDoc xmlSetNs xmlSetNsProp xmlSetProp +xmlSetStructuredErrorFunc xmlSetTreeDoc xmlSetupParserForBuffer #ifdef LIBXML_DEBUG_ENABLED @@ -1532,6 +1574,7 @@ xmlSplitQName3 xmlSprintfElementContent xmlStopParser xmlStrEqual +xmlStrPrintf xmlStrQEqual xmlStrcasecmp xmlStrcasestr @@ -1629,6 +1672,7 @@ xmlThrDefPedanticParserDefaultValue xmlThrDefRegisterNodeDefault xmlThrDefSaveNoEmptyTags xmlThrDefSetGenericErrorFunc +xmlThrDefSetStructuredErrorFunc xmlThrDefSubstituteEntitiesDefaultValue xmlThrDefTreeIndentString #ifdef LIBXML_REGEXP_ENABLED @@ -2193,6 +2237,9 @@ xmlXPathDivValues xmlXPathEqualValues #endif #ifdef LIBXML_XPATH_ENABLED +xmlXPathErr +#endif +#ifdef LIBXML_XPATH_ENABLED xmlXPathEval #endif #ifdef LIBXML_XPATH_ENABLED diff --git a/xmlreader.c b/xmlreader.c index b4c9d707..1f1176b6 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -35,6 +35,7 @@ #include #include #include +#include #include /* #define DEBUG_CALLBACKS */ @@ -3523,6 +3524,392 @@ xmlTextReaderGetErrorHandler(xmlTextReaderPtr reader, *arg = reader->errorFuncArg; } + +/************************************************************************ + * * + * New set (2.6.0) of simpler and more flexible APIs * + * * + ************************************************************************/ + +/** + * xmlTextReaderSetup: + * @reader: an XML reader + * @URL: the base URL to use for the document + * @encoding: the document encoding, or NULL + * @options: a combination of xmlParserOption(s) + * @reuse: keep the context for reuse + * + * Setup an XML reader with new options + * + * Returns 0 in case of success and -1 in case of error. + */ +static int +xmlTextReaderSetup(xmlTextReaderPtr reader, const char *URL, + const char *encoding, int options) +{ + if ((reader == NULL) || (reader->ctxt == NULL)) + return (-1); + + xmlCtxtUseOptions(reader->ctxt, options); + if (encoding != NULL) { + xmlCharEncodingHandlerPtr hdlr; + + hdlr = xmlFindCharEncodingHandler(encoding); + if (hdlr != NULL) + xmlSwitchToEncoding(reader->ctxt, hdlr); + } + if ((URL != NULL) && (reader->ctxt->input != NULL) && + (reader->ctxt->input->filename == NULL)) + reader->ctxt->input->filename = (char *) + xmlStrdup((const xmlChar *) URL); + return (0); +} + +/** + * xmlReaderForDoc: + * @cur: a pointer to a zero terminated string + * @URL: the base URL to use for the document + * @encoding: the document encoding, or NULL + * @options: a combination of xmlParserOption(s) + * + * Create an xmltextReader for an XML in-memory document. + * + * Returns the new reader or NULL in case of error. + */ +xmlTextReaderPtr +xmlReaderForDoc(const xmlChar * cur, const char *URL, const char *encoding, + int options) +{ + int len; + + if (cur == NULL) + return (NULL); + len = xmlStrlen(cur); + + return (xmlReaderForMemory + ((const char *) cur, len, URL, encoding, options)); +} + +/** + * xmlReaderForFile: + * @filename: a file or URL + * @encoding: the document encoding, or NULL + * @options: a combination of xmlParserOption(s) + * + * parse an XML file from the filesystem or the network. + * + * Returns the new reader or NULL in case of error. + */ +xmlTextReaderPtr +xmlReaderForFile(const char *filename, const char *encoding, int options) +{ + xmlTextReaderPtr reader; + + reader = xmlNewTextReaderFilename(filename); + if (reader == NULL) + return (NULL); + xmlTextReaderSetup(reader, NULL, encoding, options); + return (reader); +} + +/** + * xmlReaderForMemory: + * @buffer: a pointer to a char array + * @size: the size of the array + * @URL: the base URL to use for the document + * @encoding: the document encoding, or NULL + * @options: a combination of xmlParserOption(s) + * + * Create an xmltextReader for an XML in-memory document. + * + * Returns the new reader or NULL in case of error. + */ +xmlTextReaderPtr +xmlReaderForMemory(const char *buffer, int size, const char *URL, + const char *encoding, int options) +{ + xmlTextReaderPtr reader; + xmlParserInputBufferPtr buf; + + buf = + xmlParserInputBufferCreateMem(buffer, size, + XML_CHAR_ENCODING_NONE); + if (buf == NULL) { + return (NULL); + } + reader = xmlNewTextReader(buf, URL); + if (reader == NULL) { + xmlFreeParserInputBuffer(buf); + return (NULL); + } + xmlTextReaderSetup(reader, URL, encoding, options); + return (reader); +} + +/** + * xmlReaderForFd: + * @fd: an open file descriptor + * @URL: the base URL to use for the document + * @encoding: the document encoding, or NULL + * @options: a combination of xmlParserOption(s) + * + * Create an xmltextReader for an XML from a file descriptor. + * + * Returns the new reader or NULL in case of error. + */ +xmlTextReaderPtr +xmlReaderForFd(int fd, const char *URL, const char *encoding, int options) +{ + xmlTextReaderPtr reader; + xmlParserInputBufferPtr input; + + if (fd < 0) + return (NULL); + + input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE); + if (input == NULL) + return (NULL); + reader = xmlNewTextReader(input, URL); + if (reader == NULL) { + xmlFreeParserInputBuffer(input); + return (NULL); + } + xmlTextReaderSetup(reader, URL, encoding, options); + return (reader); +} + +/** + * xmlReaderForIO: + * @ioread: an I/O read function + * @ioclose: an I/O close function + * @ioctx: an I/O handler + * @URL: the base URL to use for the document + * @encoding: the document encoding, or NULL + * @options: a combination of xmlParserOption(s) + * + * Create an xmltextReader for an XML document from I/O functions and source. + * + * Returns the new reader or NULL in case of error. + */ +xmlTextReaderPtr +xmlReaderForIO(xmlInputReadCallback ioread, xmlInputCloseCallback ioclose, + void *ioctx, const char *URL, const char *encoding, + int options) +{ + xmlTextReaderPtr reader; + xmlParserInputBufferPtr input; + + if (ioread == NULL) + return (NULL); + + input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, + XML_CHAR_ENCODING_NONE); + if (input == NULL) + return (NULL); + reader = xmlNewTextReader(input, URL); + if (reader == NULL) { + xmlFreeParserInputBuffer(input); + return (NULL); + } + xmlTextReaderSetup(reader, URL, encoding, options); + return (reader); +} + +/** + * xmlReaderNewDoc: + * @reader: an XML reader + * @cur: a pointer to a zero terminated string + * @URL: the base URL to use for the document + * @encoding: the document encoding, or NULL + * @options: a combination of xmlParserOption(s) + * + * Setup an xmltextReader to parse an XML in-memory document. + * This reuses the existing @reader xmlTextReader. + * + * Returns 0 in case of success and -1 in case of error + */ +int +xmlReaderNewDoc(xmlTextReaderPtr reader, const xmlChar * cur, + const char *URL, const char *encoding, int options) +{ + xmlParserInputPtr stream; + + if (cur == NULL) + return (-1); + if ((reader == NULL) || (reader->ctxt == NULL)) + return (-1); + + xmlCtxtReset(reader->ctxt); + + stream = xmlNewStringInputStream(reader->ctxt, cur); + if (stream == NULL) { + return (-1); + } + inputPush(reader->ctxt, stream); + return (xmlTextReaderSetup(reader, URL, encoding, options)); +} + +/** + * xmlReaderNewFile: + * @reader: an XML reader + * @filename: a file or URL + * @encoding: the document encoding, or NULL + * @options: a combination of xmlParserOption(s) + * + * parse an XML file from the filesystem or the network. + * This reuses the existing @reader xmlTextReader. + * + * Returns 0 in case of success and -1 in case of error + */ +int +xmlReaderNewFile(xmlTextReaderPtr reader, const char *filename, + const char *encoding, int options) +{ + xmlParserInputPtr stream; + + if (filename == NULL) + return (-1); + if ((reader == NULL) || (reader->ctxt == NULL)) + return (-1); + + xmlCtxtReset(reader->ctxt); + + stream = xmlNewInputFromFile(reader->ctxt, filename); + if (stream == NULL) { + return (-1); + } + inputPush(reader->ctxt, stream); + return (xmlTextReaderSetup(reader, NULL, encoding, options)); +} + +/** + * xmlReaderNewMemory: + * @reader: an XML reader + * @buffer: a pointer to a char array + * @size: the size of the array + * @URL: the base URL to use for the document + * @encoding: the document encoding, or NULL + * @options: a combination of xmlParserOption(s) + * + * Setup an xmltextReader to parse an XML in-memory document. + * This reuses the existing @reader xmlTextReader. + * + * Returns 0 in case of success and -1 in case of error + */ +int +xmlReaderNewMemory(xmlTextReaderPtr reader, const char *buffer, int size, + const char *URL, const char *encoding, int options) +{ + xmlParserInputBufferPtr input; + xmlParserInputPtr stream; + + if ((reader == NULL) || (reader->ctxt == NULL)) + return (-1); + if (buffer == NULL) + return (-1); + + xmlCtxtReset(reader->ctxt); + + input = + xmlParserInputBufferCreateMem(buffer, size, + XML_CHAR_ENCODING_NONE); + if (input == NULL) { + return (-1); + } + + stream = xmlNewIOInputStream(reader->ctxt, input, XML_CHAR_ENCODING_NONE); + if (stream == NULL) { + xmlFreeParserInputBuffer(input); + return (-1); + } + + inputPush(reader->ctxt, stream); + return (xmlTextReaderSetup(reader, URL, encoding, options)); +} + +/** + * xmlReaderNewFd: + * @reader: an XML reader + * @fd: an open file descriptor + * @URL: the base URL to use for the document + * @encoding: the document encoding, or NULL + * @options: a combination of xmlParserOption(s) + * + * Setup an xmltextReader to parse an XML from a file descriptor. + * This reuses the existing @reader xmlTextReader. + * + * Returns 0 in case of success and -1 in case of error + */ +int +xmlReaderNewFd(xmlTextReaderPtr reader, int fd, + const char *URL, const char *encoding, int options) +{ + xmlParserInputBufferPtr input; + xmlParserInputPtr stream; + + if (fd < 0) + return (-1); + if ((reader == NULL) || (reader->ctxt == NULL)) + return (-1); + + xmlCtxtReset(reader->ctxt); + + + input = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE); + if (input == NULL) + return (-1); + stream = xmlNewIOInputStream(reader->ctxt, input, XML_CHAR_ENCODING_NONE); + if (stream == NULL) { + xmlFreeParserInputBuffer(input); + return (-1); + } + inputPush(reader->ctxt, stream); + return (xmlTextReaderSetup(reader, URL, encoding, options)); +} + +/** + * xmlReaderNewIO: + * @reader: an XML reader + * @ioread: an I/O read function + * @ioclose: an I/O close function + * @ioctx: an I/O handler + * @URL: the base URL to use for the document + * @encoding: the document encoding, or NULL + * @options: a combination of xmlParserOption(s) + * + * Setup an xmltextReader to parse an XML document from I/O functions + * and source. + * This reuses the existing @reader xmlTextReader. + * + * Returns 0 in case of success and -1 in case of error + */ +int +xmlReaderNewIO(xmlTextReaderPtr reader, xmlInputReadCallback ioread, + xmlInputCloseCallback ioclose, void *ioctx, + const char *URL, const char *encoding, int options) +{ + xmlParserInputBufferPtr input; + xmlParserInputPtr stream; + + if (ioread == NULL) + return (-1); + if ((reader == NULL) || (reader->ctxt == NULL)) + return (-1); + + xmlCtxtReset(reader->ctxt); + + input = xmlParserInputBufferCreateIO(ioread, ioclose, ioctx, + XML_CHAR_ENCODING_NONE); + if (input == NULL) + return (-1); + stream = xmlNewIOInputStream(reader->ctxt, input, XML_CHAR_ENCODING_NONE); + if (stream == NULL) { + xmlFreeParserInputBuffer(input); + return (-1); + } + inputPush(reader->ctxt, stream); + return (xmlTextReaderSetup(reader, URL, encoding, options)); +} /************************************************************************ * * * Utilities *