You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Sharad Singh <si...@gmail.com> on 2006/08/16 11:26:31 UTC

help with extending saxparser todefine some addtional rules

Hi,

I am using the SAXParser provided in the xerces.jar through which i am able
to validate xml based on dtd validations. Now I need to extend the Saxparser
functionality so that i can define some additional rules and perform
validations on that rules. Can anyone please tell me how can i do that?

for EXAMPLE i would like to validate expression : a+(b+c)
on following grammar that the brackets are properly closed and the operator
+ must have two operands....
I will have the expression written in the xml as
<mytag> a+(b+c) </mytag>

thanks in advance...
-- 
Thanks/Regards
Sharad Kumar Singh

Re: help with extending saxparser todefine some addtional rules

Posted by Scott Hinkelman <sr...@us.ibm.com>.
Sharad, Stanimir,
Needing to check additional constraints on information beyond what a given
constraint mechanism can accomplish 'out of the box' is a common problem.
While programmatic unique extensions to a given constraint mechanism may be
an option, many times it is something undesirable and the user would rather
accomplish it in a declarative way.  Something that may be of interest
here, which allows using several constraint mechanisms:

http://www-128.ibm.com/developerworks/xml/library/x-bics20/

thanks,
Scott

------------
Scott R. Hinkelman, Senior Software Engineer
IBM Software Group / Emerging Technologies
Cross-Industry SOA Foundation Standards Strategy
Office: 512.823.8097 (TL 793.8097)
Cell: 512.415.8490


                                                                           
             Stanimir                                                      
             Stamenkov                                                     
             <stanio@myrealbox                                          To 
             .com>                     j-users@xerces.apache.org           
                                                                        cc 
             08/17/2006 08:20                                              
             AM                                                    Subject 
                                       Re: help with extending saxparser   
                                       todefine some addtional rules       
             Please respond to                                             
             j-users@xerces.ap                                             
                 ache.org                                                  
                                                                           
                                                                           
                                                                           




/Sharad Singh/:

> I am using the SAXParser provided in the xerces.jar through which i am
> able to validate xml based on dtd validations. Now I need to extend the
> Saxparser functionality so that i can define some additional rules and
> perform validations on that rules. Can anyone please tell me how can i
> do that?
>
> for EXAMPLE i would like to validate expression : a+(b+c)
> on following grammar that the brackets are properly closed and the
> operator + must have two operands....
> I will have the expression written in the xml as
> <mytag> a+(b+c) </mytag>

So you have already written an |org.xml.sax.ContentHandler|
implementation to read the element text content? Then you process it
in whatever fashion you need and you could throw a
|org.xml.sax.SAXException| (you may make a subtype you handle
specifically) from your handler to terminate the parsing if
something is not valid - all handler methods are declared to throw
|org.xml.sax.SAXException|. That content validation of course is
specific to your application and is not something you could get out
of the box using standard XML validation.

--
Stanimir

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: help with extending saxparser todefine some addtional rules

Posted by Stanimir Stamenkov <st...@myrealbox.com>.
/Sharad Singh/:

> I am using the SAXParser provided in the xerces.jar through which i am 
> able to validate xml based on dtd validations. Now I need to extend the 
> Saxparser functionality so that i can define some additional rules and 
> perform validations on that rules. Can anyone please tell me how can i 
> do that?
> 
> for EXAMPLE i would like to validate expression : a+(b+c)
> on following grammar that the brackets are properly closed and the 
> operator + must have two operands....
> I will have the expression written in the xml as
> <mytag> a+(b+c) </mytag>

So you have already written an |org.xml.sax.ContentHandler| 
implementation to read the element text content? Then you process it 
in whatever fashion you need and you could throw a 
|org.xml.sax.SAXException| (you may make a subtype you handle 
specifically) from your handler to terminate the parsing if 
something is not valid - all handler methods are declared to throw 
|org.xml.sax.SAXException|. That content validation of course is 
specific to your application and is not something you could get out 
of the box using standard XML validation.

-- 
Stanimir

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org