| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include <stdio.h> |
| | #include <libxml/xmlreader.h> |
| |
|
| | #if defined(LIBXML_READER_ENABLED) && defined(LIBXML_PATTERN_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) |
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | static xmlDocPtr |
| | extractFile(const char *filename, const xmlChar *pattern) { |
| | xmlDocPtr doc; |
| | xmlTextReaderPtr reader; |
| | int ret; |
| |
|
| | |
| | |
| | |
| | reader = xmlReaderForFile(filename, NULL, 0); |
| | if (reader != NULL) { |
| | |
| | |
| | |
| | if (xmlTextReaderPreservePattern(reader, pattern, NULL) < 0) { |
| | fprintf(stderr, "%s : failed add preserve pattern %s\n", |
| | filename, (const char *) pattern); |
| | } |
| | |
| | |
| | |
| | ret = xmlTextReaderRead(reader); |
| | while (ret == 1) { |
| | ret = xmlTextReaderRead(reader); |
| | } |
| | if (ret != 0) { |
| | fprintf(stderr, "%s : failed to parse\n", filename); |
| | xmlFreeTextReader(reader); |
| | return(NULL); |
| | } |
| | |
| | |
| | |
| | doc = xmlTextReaderCurrentDoc(reader); |
| | |
| | |
| | |
| | xmlFreeTextReader(reader); |
| | } else { |
| | fprintf(stderr, "Unable to open %s\n", filename); |
| | return(NULL); |
| | } |
| | return(doc); |
| | } |
| |
|
| | int main(int argc, char **argv) { |
| | const char *filename = "test3.xml"; |
| | const char *pattern = "preserved"; |
| | xmlDocPtr doc; |
| |
|
| | if (argc == 3) { |
| | filename = argv[1]; |
| | pattern = argv[2]; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | LIBXML_TEST_VERSION |
| |
|
| | doc = extractFile(filename, (const xmlChar *) pattern); |
| | if (doc != NULL) { |
| | |
| | |
| | |
| | xmlDocDump(stdout, doc); |
| | |
| | |
| | |
| | xmlFreeDoc(doc); |
| | } |
| |
|
| | return(0); |
| | } |
| |
|
| | #else |
| | int main(void) { |
| | fprintf(stderr, "Reader, Pattern or output support not compiled in\n"); |
| | return(0); |
| | } |
| | #endif |
| |
|