Re: Odd DTD validation problem



I made the exact same changes to the example as you did (as shown below) and now our outcome is actually different, I do get the errors that I complained about in the first place:

./a.out -v msg.txt
Read file:
<?xml version="1.0"?><!DOCTYPE XSBASE SYSTEM "xsbase.dtd"><XSBASE><Command type="Connect"/></XSBASE>*
Exception caught: Validity error:
No declaration for attribute type of element Command
No declaration for element Command
No declaration for element XSBASE

The version outputs are:

[sanne@millaray ~]$ pkg-config --modversion libxml++-2.6
2.34.2
[sanne@millaray ~]$ pkg-config --modversion libxml-2.0
2.7.8

It is a stock Fedora 16 system, using these RPM's:

[sanne@millaray ~]$ rpm -qa|grep libxml2
libxml2-2.7.8-8.fc16.i686
libxml2-python-2.7.8-8.fc16.i686
libxml2-devel-2.7.8-8.fc16.i686
[sanne@millaray ~]$ rpm -qa|grep libxml++
libxml++-doc-2.34.2-1.fc16.noarch
libxml++-2.34.2-1.fc16.i686
libxml++-devel-2.34.2-1.fc16.i686

Again, these errors were NOT occurring some time ago, I just picked up development a couple of day ago on this project. And I was confronted with these errors, a short investigation of my system showed me that (in the yum.log) libxml2 was updated:

Sep 27 13:17:39 Updated: libxml2-2.7.8-8.fc16.i686
Sep 27 13:17:41 Updated: libxml2-devel-2.7.8-8.fc16.i686
Sep 27 13:17:52 Updated: libxml2-python-2.7.8-8.fc16.i686

I assume from version *-7, but I am not sure what version was installed before.

I send you the two input files I use (msg.txt and xsbase.dtd), direct.

Regards,

Sanne van der Graaf.

On 10/04/2012 06:07 AM, Kjell Ahlstedt wrote:
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]