You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Christoph Kies <ck...@gmx.de> on 2006/01/17 18:40:46 UTC

Validation

Hello everybody,

This is my first day with xerces-c++ and i think i will use it. I found no 
other c++ library at that high level. Respect and thanks to the developers.
I mangaged to complie and install it, and to parse a file.

But the validation does not behave as i expect.
I thought i would get an error, because <Task> has no member <Name>.

Can someone please help? 

---- todo.xml: ----

<?xml version="1.0" standalone="no"?>
<!DOCTYPE TodoList SYSTEM "todo.dtd">
<TodoList>
  <Task>
    <Name>do something</Name>
  </Task>
</TodoList>

---- todo.dtd: ----

<!-- DTD for Todo project -->
<!ELEMENT TodoList (Task)>
<!ELEMENT Task EMPTY>
<!-- ELEMENT Name (#PCDATA) -->

---- code: ----

	XMLPlatformUtils::Initialize();
	XercesDOMParser* parser = new XercesDOMParser();

	parser->setValidationScheme(XercesDOMParser::Val_Always);
	parser->setValidationSchemaFullChecking(true);
	parser->setIncludeIgnorableWhitespace(false);
	parser->setDoNamespaces(true);

	ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
	parser->setErrorHandler(errHandler);

	parser->parse("todo.xml");



-- 
---------------------------------------------------------------------
Christoph Kies (ckies@gmx.de)
Mobil: 0179/ 5910 805
Fax: 089/ 1488 213 020 (bis 31.03.2006)

Lindenkamp 4
59469 Ense
---------------------------------------------------------------------

Re: Validation

Posted by Christoph Kies <ck...@gmx.de>.
Am Dienstag, 17. Januar 2006 20:20 schrieb dara:

Hello Clara

> Re why you are not getting a message, are you wrapping the parse call in
> a "try" and then "catching" exceptions that may be thrown ?

Oh, i did that, but i did not want to show all the boaring code.
Nevertheless, An uncought exception would lead at least to an error (but not 
to a message)

> Running these samples and looking through their source are generally
> good ways to get started with Xerces.
> When I run "bin/DOMPrint -v=always todo.xml" with your sample xml and
> dtd, I do get a number of errors, so I would suggest to check your code
> against the sample.

Yes, thank you. I did as you told me and i found the mistake:

The sample overwrites the HandlerBase::error and shows the exception there.
My code uses the default HandlerBase::error which does nothing.

When I wrote my code, i followed the DOM Programming Guide.
The example on page (201 and 202) in the PDF-document
looked to me like it trys to handle all errors, cause there where many 
try-catch blocks.
I asked myself, if the default HandlerBase would rethrow exceptions and i 
tryed it out: it did in some cases! I have not found a hint, that there is a 
difference between default handling of error and fatalerror. Meanwhile i 
looked at HanderBase.hpp and found the documentation there. 

Thank You!
Christoph

-- 
---------------------------------------------------------------------
Christoph Kies (ckies@gmx.de)
Mobil: 0179/ 5910 805
Fax: 089/ 1488 213 020 (bis 31.03.2006)

Lindenkamp 4
59469 Ense
---------------------------------------------------------------------

Re: Validation

Posted by dara <da...@risaris.com>.
Christoph Kies wrote:

>Am Dienstag, 17. Januar 2006 18:51 schrieb dara:
>  
>
>>Hi Christoph,
>>
>>I've not used DTDs but it looks to me like the definition for "Name" in
>>the dtd provided is a comment !
>>    
>>
>
>Hi Clara,
>i commented <Name> out because i _want_ to get en error.
>My question is: Why do i _not_ get an error?
>
>Thank you, for showing me, that i have to point that out.
>  
>
Hi again Christoph

Ah indeed, apologies, I missed that important point  :)

Re why you are not getting a message, are you wrapping the parse call in 
a "try" and then "catching" exceptions that may be thrown ?

Ala :

     try
        {
            parser->parse(gXmlFile);
        }
        catch (const OutOfMemoryException&)
        {
            XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" <<
    XERCES_STD_QUALIFIER endl;
            errorsOccured = true;
        }
        catch (const XMLException& e)
        {
            XERCES_STD_QUALIFIER cerr << "An error occurred during
    parsing\n   Message: "
                 << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
            errorsOccured = true;
        }

This is from the DOMPrint example in xerces-c-src_2_7_0/samples/DOMPrint/

Running these samples and looking through their source are generally 
good ways to get started with Xerces.

When I run "bin/DOMPrint -v=always todo.xml" with your sample xml and 
dtd, I do get a number of errors, so I would suggest to check your code 
against the sample.

Regards

Dara


Re: Validation

Posted by Christoph Kies <ck...@gmx.de>.
Am Dienstag, 17. Januar 2006 18:51 schrieb dara:
> Hi Christoph,
>
> I've not used DTDs but it looks to me like the definition for "Name" in
> the dtd provided is a comment !

Hi Clara,
i commented <Name> out because i _want_ to get en error.
My question is: Why do i _not_ get an error?

Thank you, for showing me, that i have to point that out.
-- 
---------------------------------------------------------------------
Christoph Kies (ckies@gmx.de)
Mobil: 0179/ 5910 805
Fax: 089/ 1488 213 020 (bis 31.03.2006)

Lindenkamp 4
59469 Ense
---------------------------------------------------------------------

Re: Validation

Posted by dara <da...@risaris.com>.
Hi Christoph,

I've not used DTDs but it looks to me like the definition for "Name" in 
the dtd provided is a comment !

Thus, the parser would give out, basically it would be saying you've 
added a "Name" element in your document but it's not defined in your DTD.

:)

Regards

Dm

Christoph Kies wrote:

>Hello everybody,
>
>This is my first day with xerces-c++ and i think i will use it. I found no 
>other c++ library at that high level. Respect and thanks to the developers.
>I mangaged to complie and install it, and to parse a file.
>
>But the validation does not behave as i expect.
>I thought i would get an error, because <Task> has no member <Name>.
>
>Can someone please help? 
>
>---- todo.xml: ----
>
><?xml version="1.0" standalone="no"?>
><!DOCTYPE TodoList SYSTEM "todo.dtd">
><TodoList>
>  <Task>
>    <Name>do something</Name>
>  </Task>
></TodoList>
>
>---- todo.dtd: ----
>
><!-- DTD for Todo project -->
><!ELEMENT TodoList (Task)>
><!ELEMENT Task EMPTY>
><!-- ELEMENT Name (#PCDATA) -->
>
>---- code: ----
>
>	XMLPlatformUtils::Initialize();
>	XercesDOMParser* parser = new XercesDOMParser();
>
>	parser->setValidationScheme(XercesDOMParser::Val_Always);
>	parser->setValidationSchemaFullChecking(true);
>	parser->setIncludeIgnorableWhitespace(false);
>	parser->setDoNamespaces(true);
>
>	ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
>	parser->setErrorHandler(errHandler);
>
>	parser->parse("todo.xml");
>
>
>
>  
>


-- 
Regards,

Dara Mulvihill,

Rísarís Ltd,

http://www.risaris.com

++353 404 64009