[xml] problem using xmlTextReaderName ?



I'm new to XML and LIBXML.
LIBXML 2.6-4 in OpenVMS environment.
I'm doing some simple tests, but I have a strange problem.

I get the error:

I/O error : No such file or directory

when I run the following simple code (below there are also
a simple XML file, DTD file and output of the run).

The code seems to work fine also if there is the above error.

The error seems to happen on the line that I have quoted with ***>>>


Francesco

#include <stdlib.h>
#include <stdio.h>
#include <libxml/xmlreader.h>

static void processNode( xmlTextReaderPtr reader )
{

  xmlChar *name, *value;
  name = xmlTextReaderName( reader );
  if( name != NULL ) printf( "element '%s'\n", name );
  xmlFree( name );

}

void streamXMLFile(char *filename)

{

 xmlTextReaderPtr reader;
 int ret = 0;

 reader = xmlNewTextReaderFilename( filename );

 if( reader != NULL )
 {

    ret = xmlTextReaderSetParserProp( reader, XML_PARSER_VALIDATE, 1 );
    printf( "ret = %d\n", ret );
***>>>    ret = xmlTextReaderRead( reader );
    printf( "ret = %d\n", ret );
    while( ret == 1 )
    {
       processNode( reader );
       ret = xmlTextReaderRead( reader );
       printf( "ret = %d\n", ret );
    }

    xmlFreeTextReader(reader);

 else printf("Unable to open %s\n", filename);

}


int main(int argc, char **argv) {
    if (argc != 2)
        return(1);

    /*
     * this initialize the library and check potential ABI mismatches
     * between the version it was compiled for and the actual shared
     * library used.
     */
    LIBXML_TEST_VERSION

    streamXMLFile(argv[1]);

    /*
     * Cleanup function for the XML library.
     */
    xmlCleanupParser();
    /*
     * this is to debug memory for regression tests
     */
    xmlMemoryDump();
    return(0);
}

XML FILE:

<?xml version="1.0"?>
<!DOCTYPE doc SYSTEM "doc.dtd">

<doc>
  <src ref="foo"/>
  <dest id="foo"/>
  <src ref="foo"/>
</doc>


DTD FILE

<?xml version="1.0" encoding="ISO-8859-1"?>
<!ELEMENT doc (src | dest)*>
<!ELEMENT src EMPTY>
<!ELEMENT dest EMPTY>
<!ATTLIST src ref IDREF #IMPLIED>
<!ATTLIST dest id ID #IMPLIED>

Program OUTPUT:

ret = 0
I/O error : No such file or directory
ret = 1
element 'doc'
ret = 1
element 'doc'
ret = 1
element '#text'
ret = 1
element 'src'
ret = 1
element '#text'
ret = 1
element 'dest'
ret = 1
element '#text'
ret = 1
element 'src'
ret = 1
element '#text'
ret = 1
element 'doc'
ret = 0




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]