Re: Odd DTD validation problem



This is strange!  I replaced

   parser.parse_file(filepath);

in examples/dom_parser/main.cc with

    std::ifstream in(filepath.c_str());
    std::stringstream iss;
    char c;
    while (in.get(c))
      iss << c;
    std::cout << "Read file:" << std::endl << iss.str() << "*" << std::endl;
    parser.parse_stream(iss);

It works as expected. It throws an exception and shows validation errors only when I deliberately insert errors in the xml file.

Which version of libxml++ do you use? (pkg-config --modversion libxml++-2.6) I use the latest source code from the git repository, which includes some modifications done after version 2.35.3. I use libxml2 version 2.8.0. (pkg-config --modversion libxml-2.0)

Can you please supply both an xml file that generates unexpected validation errors, and the corresponding dtd file. Preferably as attached files, so I can get them exactly as they are, with no spaces or newlines added or removed. Added or removed spaces and newlines should in most cases make no difference, but just in case.

Kjell

2012-10-04 00:08, Sanne Graaf skrev:

I did the same just a moment ago, I used the suggested correct command line for xmllint:

xmllint msg.txt --dtdvalid xsbase.dtd

and the contents of the msg.txt is:

<?xml version="1.0"?><!DOCTYPE XSBASE SYSTEM "xsbase.dtd"><XSBASE><Command type="Connect"/></XSBASE>


and the output of xmllint is:

<?xml version="1.0"?>
<!DOCTYPE XSBASE SYSTEM "xsbase.dtd">
<XSBASE><Command type="Connect"/></XSBASE>

if I deliberately make an error in the msg.txt I receive an error as one should expect, but without a deliberate error, xmllint likes the xml, so no errors or warnings..

I tried the same using one of the libxml++ examples, the dom_parser example , using my msg.txt and the dtd (xsbase.dtd), again no problem, no errors, I used the example program with the -v option. I also introduced again an error to see what happens, and the example nicely reports an error.

There is only ONE big difference between the example and my code that doesn't work anymore, the example uses parser.parse_file(), my code uses parser.parse_stream() as the data comes in though a network socket. But when I print the buffer JUST before parsing, the contents of the buffer is correct. (the same as the contents of the msg.txt file)

--- [begin snippet] ---
    xmlpp::DomParser parser;

    parser.set_validate();    // doesn't work anymore
    parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.

// copy the received bytes to a buffer in the case the message is received partially

    boost::array<char, 8192>::iterator it;
    for (it = buffer.begin(); it != buffer.begin()+numread; it++) {
                commandbuffer[NumBytesInBuffer++] = *it;
    }

    std::stringstream iss;
    iss << commandbuffer.data();
   
    cout << "CommandBuffer Data: " << iss.str() << endl;
   
    try {   
        parser.parse_stream(iss);
--- [end snippet] ---

The last line throws the exception because the xml does not seem valid...


Regards,

Sanne van der Graaf.



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