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.
On 10/03/2012 02:13 PM, Kjell Ahlstedt wrote:
I made some tests with the small test
case and xml and dtd files at
http://git.gnome.org/browse/libxml++/tree/examples/dom_parser
The file example_invalid.xml does not validate against
example.dtd (deliberate errors).
xmllint example_invalid.xml --dtdvalid
does not print error messages.
xmllint example_invalid.xml --dtdvalid example.dtd
and
xmllint --dtdvalid example.dtd example_invalid.xml
do print error messages.
It seems that xmllint does not validate unless you specify the
name of the dtd file on the command line. What happens if you
try
xmllint test.xml --dtdvalid myapp.dtd
or
xmllint --dtdvalid myapp.dtd test.xml
?
Kjell
2012-10-03 02:16, Sanne Graaf skrev:
Hello everybody,
Lately my Fedora 16 auto-upgraded libxml2 from a previous
version to the latest rpm libxml2-2.7.8-8.fc16.i686, and
suddenly the dtd validation starts to complain about missing
declarations in the DTD file. Before this upgrade everything
worked fine. And of course when I disable the validation it also
works fine, but that is not the idea. I don't use libxml2
directly, I use libxml++.
When I use tools like xmllint the xml message also doesn't have
any problems, so my conclusion is that the problem is not in
libxml2, but libxml++ keeps on insisting the message is wrong.
Example message:
<?xml version="1.0"?><!DOCTYPE MYAPP SYSTEM
"myapp.dtd"><MYAPP><Command
type="Connect"/></MYAPP>
Gives these errors:
Validity error:
Line 1, column 76 (error):
No declaration for attribute type of element Command
Line 1, column 78 (error):
No declaration for element Command
Line 1, column 87 (error):
No declaration for element MYAPP
All the needed elements are in the dtd file, and like said
before a command like:
xmllint test.xml -dtdvalid
doesn't give any problems.
I tried recompiling the latest versions of libxml2 and libxml++
and use these in my app, but the result is the same (only the
Line and column numbers of the error are now added)
Does anybody have a clue why this is suddenly happening?
|