You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "mario.gonzalez" <ma...@avega.se> on 2002/07/25 16:10:52 UTC
Some questions on DOM parsing and schema validation
Hi,
I have some questions regarding the DOM parsing API and schema validation:
(I am trying to parse an XML-file and validate it against its schema, pretty basic.
I'm using the XercesDOMParser for this.)
1. As I am validating the XML document against its schema, I am very interested in
knowing if the document somehow fails to conform to the rules stated in the schema.
Everything works fine (I can tell that the schema is used, no exceptions are thrown etc),
but when I purpously introduce errors to the XML document that break those rules,
well...nothing happens...no exceptions, nothing.
I have gone through the API, and switched on all the schema checking and validation options
I could find. The "parse" is inside a try...catch... block, so I should get notified if
any exceptions are thrown (I'm eaven catching (...)). The only indication of something
going wrong (somewhere), was that parser->getErrorCount() returned 1. What I want to know is,
how do I get a description of the error that occurred? (I'm using the default HandlerBase as
the error handler...should I use something else, or am I just missing out on something?). Obviously, the validation recognizes when the rules are broken...I just need to know what, why and when.
2. Is there any way to get the metadata (specified in the schema), for any given node in
a DOM structure (after or during parsing). The specific information that I want to get a hold of
is the datatype information associated with an element, for example "xsd:string" and so on (see below).
(.xsd)
...
<xsd:element name="description" type='xsd:string' minOccurs='1' maxOccurs='1'/>
...
(.xml)
...
<description>A simple repair session</description>
...
So, looking at the snippets above, whenever I encounter the element node "name", I would
want to be able to find out that its type is 'xsd:string'. Is this possible?
Any help on the above matters is greatly appreciated
Best regards
Mario
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Some questions on DOM parsing and schema validation
Posted by Gareth Reakes <ga...@decisionsoft.com>.
Hi,
On Thu, 25 Jul 2002, mario.gonzalez wrote:
> Hi,
>
> I have some questions regarding the DOM parsing API and schema validation:
>
> (I am trying to parse an XML-file and validate it against its schema, pretty basic.
> I'm using the XercesDOMParser for this.)
>
> 1. As I am validating the XML document against its schema, I am very interested in
> knowing if the document somehow fails to conform to the rules stated in the schema.
> Everything works fine (I can tell that the schema is used, no exceptions are thrown etc),
> but when I purpously introduce errors to the XML document that break those rules,
> well...nothing happens...no exceptions, nothing.
>
> I have gone through the API, and switched on all the schema checking and validation options
> I could find. The "parse" is inside a try...catch... block, so I should get notified if
> any exceptions are thrown (I'm eaven catching (...)). The only indication of something
> going wrong (somewhere), was that parser->getErrorCount() returned 1. What I want to know is,
> how do I get a description of the error that occurred? (I'm using the default HandlerBase as
> the error handler...should I use something else, or am I just missing out on something?). Obviously, the validation recognizes when the rules are broken...I just need to know what, why and when.
The DefaultHandler implementations do nothing. Take a look in one of the
examples like SAXCount and look at the file SAXCountHandlers. There is an
example of overriding error fatalError and warning in there.
>
>
> 2. Is there any way to get the metadata (specified in the schema), for any given node in
> a DOM structure (after or during parsing). The specific information that I want to get a hold of
> is the datatype information associated with an element, for example "xsd:string" and so on (see below).
You can get the information during parsing. For an example with SAX take a
look at SEnumVal. If you wanted to do this with DOM you would have to
override the parser. If you wanted the information associated with the
nodes after parse you would have to store that yourself (you could use
UserData).
hope this helps
Gareth
--
Gareth Reakes, Head of Product Development
DecisionSoft Ltd. http://www.decisionsoft.com
Office: +44 (0) 1865 203192
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org