123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #include <stdio.h>
- #include <libxml/xmlreader.h>
- #ifdef LIBXML_READER_ENABLED
- static void
- processNode(xmlTextReaderPtr reader) {
- const xmlChar *name, *value;
- name = xmlTextReaderConstName(reader);
- if (name == NULL)
- name = BAD_CAST "--";
- value = xmlTextReaderConstValue(reader);
- printf("%d %d %s %d %d",
- xmlTextReaderDepth(reader),
- xmlTextReaderNodeType(reader),
- name,
- xmlTextReaderIsEmptyElement(reader),
- xmlTextReaderHasValue(reader));
- if (value == NULL)
- printf("\n");
- else {
- if (xmlStrlen(value) > 40)
- printf(" %.40s...\n", value);
- else
- printf(" %s\n", value);
- }
- }
- static void
- streamFile(const char *filename) {
- xmlTextReaderPtr reader;
- int ret;
-
- reader = xmlReaderForFile(filename, NULL,
- XML_PARSE_DTDATTR |
- XML_PARSE_NOENT |
- XML_PARSE_DTDVALID);
- if (reader != NULL) {
- ret = xmlTextReaderRead(reader);
- while (ret == 1) {
- processNode(reader);
- ret = xmlTextReaderRead(reader);
- }
-
- if (xmlTextReaderIsValid(reader) != 1) {
- fprintf(stderr, "Document %s does not validate\n", filename);
- }
- xmlFreeTextReader(reader);
- if (ret != 0) {
- fprintf(stderr, "%s : failed to parse\n", filename);
- }
- } else {
- fprintf(stderr, "Unable to open %s\n", filename);
- }
- }
- int main(int argc, char **argv) {
- if (argc != 2)
- return(1);
-
- LIBXML_TEST_VERSION
- streamFile(argv[1]);
-
- xmlCleanupParser();
-
- xmlMemoryDump();
- return(0);
- }
- #else
- int main(void) {
- fprintf(stderr, "XInclude support not compiled in\n");
- exit(1);
- }
- #endif
|