From ffa7b7e2ba3841a80f9c5a69e89cc4b4e457840b Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Fri, 5 Dec 2003 16:10:21 +0000 Subject: [PATCH] fixed the pattern interfaces but not yet the parser to handle the * pattern.c xmlreader.c xmllint.c include/libxml/pattern.h include/libxml/xmlreader.h: fixed the pattern interfaces but not yet the parser to handle the namespaces. * doc/examples/reader3.c doc/*: fixed the example, rebuilt the docs. Daniel --- ChangeLog | 7 +++++++ doc/APIchunk11.html | 2 ++ doc/APIfunctions.html | 2 ++ doc/examples/reader3.c | 2 +- doc/html/libxml-xmlreader.html | 6 +++--- doc/libxml2-api.xml | 4 +++- doc/libxml2-refs.xml | 4 ++++ include/libxml/pattern.h | 3 ++- include/libxml/xmlreader.h | 3 ++- pattern.c | 24 +++++++++++++++++++----- python/libxml2class.txt | 1 - xmllint.c | 2 +- xmlreader.c | 7 +++++-- 13 files changed, 51 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c1e255e..62e5d501 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Dec 5 17:07:29 CET 2003 Daniel Veillard + + * pattern.c xmlreader.c xmllint.c include/libxml/pattern.h + include/libxml/xmlreader.h: fixed the pattern interfaces + but not yet the parser to handle the namespaces. + * doc/examples/reader3.c doc/*: fixed the example, rebuilt the docs. + Fri Dec 5 15:49:44 CET 2003 Daniel Veillard * globals.c xmlwriter.c doc/apibuild.py include/libxml/globals.h diff --git a/doc/APIchunk11.html b/doc/APIchunk11.html index eea44c91..0c953d80 100644 --- a/doc/APIchunk11.html +++ b/doc/APIchunk11.html @@ -184,7 +184,9 @@ A:link, A:visited, A:active { text-decoration: underline } startElementNsSAX2Func
xmlLoadCatalog
xmlLoadCatalogs
+xmlPatterncompile
xmlSAX2StartElementNs
+xmlTextReaderPreservePattern
xmlValidateDtd
delayed
xmlOutputBufferWrite
xmlOutputBufferWriteString
diff --git a/doc/APIfunctions.html b/doc/APIfunctions.html index 5832dda8..c21ab2fd 100644 --- a/doc/APIfunctions.html +++ b/doc/APIfunctions.html @@ -682,9 +682,11 @@ A:link, A:visited, A:active { text-decoration: underline } startElementSAXFunc
xlinkExtendedLinkFunk
xlinkExtendedLinkSetFunk
+xmlPatterncompile
xmlSAX2StartElement
xmlSAX2StartElementNs
xmlSAX2StartElementNs
+xmlTextReaderPreservePattern
xmlValidGetPotentialChildren
xmlValidGetValidElements

Type const xmlListPtr:

xmlListCopy
diff --git a/doc/examples/reader3.c b/doc/examples/reader3.c index 715deeec..e9815cd8 100644 --- a/doc/examples/reader3.c +++ b/doc/examples/reader3.c @@ -35,7 +35,7 @@ extractFile(const char *filename, const xmlChar *pattern) { /* * add the pattern to preserve */ - if (xmlTextReaderPreservePattern(reader, pattern) < 0) { + if (xmlTextReaderPreservePattern(reader, pattern, NULL) < 0) { fprintf(stderr, "%s : failed add preserve pattern %s\n", filename, (const char *) pattern); } diff --git a/doc/html/libxml-xmlreader.html b/doc/html/libxml-xmlreader.html index 083cd33e..17bd9957 100644 --- a/doc/html/libxml-xmlreader.html +++ b/doc/html/libxml-xmlreader.html @@ -79,7 +79,7 @@ void xmlTextReaderErrorFunc (void * arg,

int	xmlTextReaderNormalization	(xmlTextReaderPtr reader)
xmlChar *	xmlTextReaderPrefix	(xmlTextReaderPtr reader)
xmlNodePtr	xmlTextReaderPreserve	(xmlTextReaderPtr reader)
-
int	xmlTextReaderPreservePattern	(xmlTextReaderPtr reader, 
const xmlChar * pattern)
+
int	xmlTextReaderPreservePattern	(xmlTextReaderPtr reader, 
const xmlChar * pattern,
const xmlChar ** namespaces)
int	xmlTextReaderQuoteChar		(xmlTextReaderPtr reader)
int	xmlTextReaderRead		(xmlTextReaderPtr reader)
int	xmlTextReaderReadAttributeValue	(xmlTextReaderPtr reader)
@@ -249,9 +249,9 @@ void xmlTextReaderErrorFunc (void * arg,
const char * msg,

A shorthand reference to the namespace associated with the node.

reader:the xmlTextReaderPtr used
Returns:the prefix or NULL if not available

Function: xmlTextReaderPreserve

xmlNodePtr	xmlTextReaderPreserve	(xmlTextReaderPtr reader)

current node being accessed by the xmlTextReader. This is dangerous because the underlying node may be destroyed on the next Reads.

-
reader:the xmlTextReaderPtr used
Returns:the xmlNodePtr or NULL in case of error.

Function: xmlTextReaderPreservePattern

int	xmlTextReaderPreservePattern	(xmlTextReaderPtr reader, 
const xmlChar * pattern)
+
reader:the xmlTextReaderPtr used
Returns:the xmlNodePtr or NULL in case of error.

Function: xmlTextReaderPreservePattern

int	xmlTextReaderPreservePattern	(xmlTextReaderPtr reader, 
const xmlChar * pattern,
const xmlChar ** namespaces)

This tells the XML Reader to preserve all nodes matched by the pattern. The caller must also use xmlTextReaderCurrentDoc() to keep an handle on the resulting document once parsing has finished

-
reader:the xmlTextReaderPtr used
pattern:an XPath subset pattern
Returns:a positive number in case of success and -1 in case of error

Function: xmlTextReaderQuoteChar

int	xmlTextReaderQuoteChar		(xmlTextReaderPtr reader)
+
reader:the xmlTextReaderPtr used
pattern:an XPath subset pattern
namespaces:the prefix definitions, array of [URI, prefix] or NULL
Returns:a positive number in case of success and -1 in case of error

Function: xmlTextReaderQuoteChar

int	xmlTextReaderQuoteChar		(xmlTextReaderPtr reader)

The quotation mark character used to enclose the value of an attribute.

reader:the xmlTextReaderPtr used
Returns:" or ' and -1 in case of error

Function: xmlTextReaderRead

int	xmlTextReaderRead		(xmlTextReaderPtr reader)

Moves the position of the current instance to the next node in the stream, exposing its properties.

diff --git a/doc/libxml2-api.xml b/doc/libxml2-api.xml index 274a445d..155ba3f4 100644 --- a/doc/libxml2-api.xml +++ b/doc/libxml2-api.xml @@ -10024,11 +10024,12 @@ actually an xmlCharEncoding'/> - Compile a pattern + Compile a pattern. + Set and return the previous value for enabling pedantic warnings. @@ -11764,6 +11765,7 @@ actually an xmlCharEncoding'/> + The quotation mark character used to enclose the value of an attribute. diff --git a/doc/libxml2-refs.xml b/doc/libxml2-refs.xml index 1088559a..3169d24f 100644 --- a/doc/libxml2-refs.xml +++ b/doc/libxml2-refs.xml @@ -7085,9 +7085,11 @@ + + @@ -18242,7 +18244,9 @@ + + diff --git a/include/libxml/pattern.h b/include/libxml/pattern.h index bac6b4ef..9db9c4e7 100644 --- a/include/libxml/pattern.h +++ b/include/libxml/pattern.h @@ -36,7 +36,8 @@ XMLPUBFUN void XMLCALL XMLPUBFUN xmlPatternPtr XMLCALL xmlPatterncompile (const xmlChar *pattern, xmlDict *dict, - int flags); + int flags, + const xmlChar **namespaces); XMLPUBFUN int XMLCALL xmlPatternMatch (xmlPatternPtr comp, xmlNodePtr node); diff --git a/include/libxml/xmlreader.h b/include/libxml/xmlreader.h index c9c79899..f4add562 100644 --- a/include/libxml/xmlreader.h +++ b/include/libxml/xmlreader.h @@ -198,7 +198,8 @@ XMLPUBFUN xmlNodePtr XMLCALL xmlTextReaderPreserve (xmlTextReaderPtr reader); XMLPUBFUN int XMLCALL xmlTextReaderPreservePattern(xmlTextReaderPtr reader, - const xmlChar *pattern); + const xmlChar *pattern, + const xmlChar **namespaces); XMLPUBFUN xmlDocPtr XMLCALL xmlTextReaderCurrentDoc (xmlTextReaderPtr reader); XMLPUBFUN xmlNodePtr XMLCALL diff --git a/pattern.c b/pattern.c index 01f974c3..5cac2df0 100644 --- a/pattern.c +++ b/pattern.c @@ -73,6 +73,8 @@ struct _xmlPatParserContext { xmlDictPtr dict; /* the dictionnary if any */ xmlPatternPtr comp; /* the result */ xmlNodePtr elem; /* the current node if any */ + const xmlChar **namespaces; /* the namespaces definitions */ + int nb_namespaces; /* the number of namespaces */ }; /************************************************************************ @@ -149,14 +151,16 @@ xmlFreePatternList(xmlPatternPtr comp) { /** * xmlNewPatParserContext: * @pattern: the pattern context - * @ctxt: the transformation context, if done at run-time + * @dict: the inherited dictionnary or NULL + * @namespaces: the prefix definitions, array of [URI, prefix] or NULL * * Create a new XML pattern parser context * * Returns the newly allocated xmlPatParserContextPtr or NULL in case of error */ static xmlPatParserContextPtr -xmlNewPatParserContext(const xmlChar *pattern, xmlDictPtr dict) { +xmlNewPatParserContext(const xmlChar *pattern, xmlDictPtr dict, + const xmlChar **namespaces) { xmlPatParserContextPtr cur; if (pattern == NULL) @@ -172,6 +176,14 @@ xmlNewPatParserContext(const xmlChar *pattern, xmlDictPtr dict) { cur->dict = dict; cur->cur = pattern; cur->base = pattern; + if (namespaces != NULL) { + int i; + for (i = 0;namespaces[2 * i] != NULL;i++); + cur->nb_namespaces = i; + } else { + cur->nb_namespaces = 0; + } + cur->namespaces = namespaces; return(cur); } @@ -871,17 +883,19 @@ error: * @pattern: the pattern to compile * @dict: an optional dictionnary for interned strings * @flags: compilation flags, undefined yet + * @namespaces: the prefix definitions, array of [URI, prefix] or NULL * - * Compile a pattern + * Compile a pattern. * * Returns the compiled for of the pattern or NULL in case of error */ xmlPatternPtr -xmlPatterncompile(const xmlChar *pattern, xmlDict *dict, int flags) { +xmlPatterncompile(const xmlChar *pattern, xmlDict *dict, int flags, + const xmlChar **namespaces) { xmlPatternPtr ret = NULL; xmlPatParserContextPtr ctxt = NULL; - ctxt = xmlNewPatParserContext(pattern, dict); + ctxt = xmlNewPatParserContext(pattern, dict, namespaces); if (ctxt == NULL) goto error; ret = xmlNewPattern(); if (ret == NULL) goto error; diff --git a/python/libxml2class.txt b/python/libxml2class.txt index b73910b5..271dbebc 100644 --- a/python/libxml2class.txt +++ b/python/libxml2class.txt @@ -739,7 +739,6 @@ Class xmlTextReader(xmlTextReaderCore) Normalization() Prefix() Preserve() - PreservePattern() QuoteChar() Read() ReadAttributeValue() diff --git a/xmllint.c b/xmllint.c index 8cc8e581..37dc72e7 100644 --- a/xmllint.c +++ b/xmllint.c @@ -1881,7 +1881,7 @@ main(int argc, char **argv) { #endif /* LIBXML_SCHEMAS_ENABLED */ #ifdef LIBXML_PATTERN_ENABLED if (pattern != NULL) { - patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0); + patternc = xmlPatterncompile((const xmlChar *) pattern, NULL, 0, NULL); if (patternc == NULL) { xmlGenericError(xmlGenericErrorContext, "Pattern %s failed to compile\n", pattern); diff --git a/xmlreader.c b/xmlreader.c index 0295ddc3..0ce19db7 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -3554,6 +3554,7 @@ xmlTextReaderPreserve(xmlTextReaderPtr reader) { * xmlTextReaderPreservePattern: * @reader: the xmlTextReaderPtr used * @pattern: an XPath subset pattern + * @namespaces: the prefix definitions, array of [URI, prefix] or NULL * * This tells the XML Reader to preserve all nodes matched by the * pattern. The caller must also use xmlTextReaderCurrentDoc() to @@ -3562,13 +3563,15 @@ xmlTextReaderPreserve(xmlTextReaderPtr reader) { * Returns a positive number in case of success and -1 in case of error */ int -xmlTextReaderPreservePattern(xmlTextReaderPtr reader, const xmlChar *pattern) { +xmlTextReaderPreservePattern(xmlTextReaderPtr reader, const xmlChar *pattern, + const xmlChar **namespaces) +{ xmlPatternPtr comp; if ((reader == NULL) || (pattern == NULL)) return(-1); - comp = xmlPatterncompile(pattern, reader->dict, 0); + comp = xmlPatterncompile(pattern, reader->dict, 0, namespaces); if (comp == NULL) return(-1);