You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by ajay bhadauria <ab...@yahoo.com> on 2008/10/31 16:55:59 UTC

how to xpath when schema validation fails.

Hi,

I need help.

I am doing xml document validation against schema using xalan 2.7.1. I am providing dom to validate API of xalan 2.7.1. 

So when dcoument validation fails on some element of the xml document , how do we construct xpath from root element of the document to the element where error occuurred. 


Thanks a lot.

Ajay Bhadauria



      

Re: how to xpath when schema validation fails.

Posted by ajay bhadauria <ab...@yahoo.com>.
Michael,

In ErrorHandler, I tried to implement to query the property but at run time it gave me belwo error. It looks like that I am querying the wrong property. I tried to find the appropriate property but could not .

What property should I use so that I can get the current element node when validator throws error ?  Please find the attached file for reference .

Progrma  started
instance error org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'Doc:Id1'. One of '{"urn:swift:xsd:swift.eni$camt.028.001.02":Id}' is expected.
org.xml.sax.SAXNotRecognizedException: http://apache.org/xml/properties/dom/current-element-node
Program ended


Thanks 
ajay.


--- On Sun, 11/9/08, Michael Glavassevich <mr...@ca.ibm.com> wrote:

> From: Michael Glavassevich <mr...@ca.ibm.com>
> Subject: Re: how to xpath when schema validation fails.
> To: j-users@xerces.apache.org
> Cc: xalan-j-users@xml.apache.org, abhadauria@yahoo.com
> Date: Sunday, November 9, 2008, 2:45 AM
> Hi Ajay,
> 
> ajay bhadauria <ab...@yahoo.com> wrote on
> 11/07/2008 03:17:21 PM:
> 
> > Michael,
> >
> > Thanks for response and explanation.
> >
> > But can we use current-element-node property which
> could be set to
> > javax.xml.validation.Validator using setProperty and
> we get the node
> > which is in error during validation?
> 
> The current element node is the current element being
> visited by the
> validator. It's not necessarily where the error is
> located though often is.
> I suggested querying this property in your error handler
> because it's the
> best approximation available from the validator at that
> point.
> 
> > Once we get the node and then with getParaentNode
> recursively
> > and get the complete xpath ?
> 
> That will give you an XPath for the current element node,
> but not
> necessarily an XPath which points to the location of the
> error which was
> reported. This certainly never works for attributes.
> 
> > Regards
> > Ajay
> 
> Thanks.
> 
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org


      

Re: how to xpath when schema validation fails.

Posted by ajay bhadauria <ab...@yahoo.com>.
Michael,

In ErrorHandler, I tried to implement to query the property but at run time it gave me belwo error. It looks like that I am querying the wrong property. I tried to find the appropriate property but could not .

What property should I use so that I can get the current element node when validator throws error ?  Please find the attached file for reference .

Progrma  started
instance error org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'Doc:Id1'. One of '{"urn:swift:xsd:swift.eni$camt.028.001.02":Id}' is expected.
org.xml.sax.SAXNotRecognizedException: http://apache.org/xml/properties/dom/current-element-node
Program ended


Thanks 
ajay.


--- On Sun, 11/9/08, Michael Glavassevich <mr...@ca.ibm.com> wrote:

> From: Michael Glavassevich <mr...@ca.ibm.com>
> Subject: Re: how to xpath when schema validation fails.
> To: j-users@xerces.apache.org
> Cc: xalan-j-users@xml.apache.org, abhadauria@yahoo.com
> Date: Sunday, November 9, 2008, 2:45 AM
> Hi Ajay,
> 
> ajay bhadauria <ab...@yahoo.com> wrote on
> 11/07/2008 03:17:21 PM:
> 
> > Michael,
> >
> > Thanks for response and explanation.
> >
> > But can we use current-element-node property which
> could be set to
> > javax.xml.validation.Validator using setProperty and
> we get the node
> > which is in error during validation?
> 
> The current element node is the current element being
> visited by the
> validator. It's not necessarily where the error is
> located though often is.
> I suggested querying this property in your error handler
> because it's the
> best approximation available from the validator at that
> point.
> 
> > Once we get the node and then with getParaentNode
> recursively
> > and get the complete xpath ?
> 
> That will give you an XPath for the current element node,
> but not
> necessarily an XPath which points to the location of the
> error which was
> reported. This certainly never works for attributes.
> 
> > Regards
> > Ajay
> 
> Thanks.
> 
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org


      

Re: how to xpath when schema validation fails.

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Ajay,

ajay bhadauria <ab...@yahoo.com> wrote on 11/07/2008 03:17:21 PM:

> Michael,
>
> Thanks for response and explanation.
>
> But can we use current-element-node property which could be set to
> javax.xml.validation.Validator using setProperty and we get the node
> which is in error during validation?

The current element node is the current element being visited by the
validator. It's not necessarily where the error is located though often is.
I suggested querying this property in your error handler because it's the
best approximation available from the validator at that point.

> Once we get the node and then with getParaentNode recursively
> and get the complete xpath ?

That will give you an XPath for the current element node, but not
necessarily an XPath which points to the location of the error which was
reported. This certainly never works for attributes.

> Regards
> Ajay

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Re: how to xpath when schema validation fails.

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Ajay,

ajay bhadauria <ab...@yahoo.com> wrote on 11/07/2008 03:17:21 PM:

> Michael,
>
> Thanks for response and explanation.
>
> But can we use current-element-node property which could be set to
> javax.xml.validation.Validator using setProperty and we get the node
> which is in error during validation?

The current element node is the current element being visited by the
validator. It's not necessarily where the error is located though often is.
I suggested querying this property in your error handler because it's the
best approximation available from the validator at that point.

> Once we get the node and then with getParaentNode recursively
> and get the complete xpath ?

That will give you an XPath for the current element node, but not
necessarily an XPath which points to the location of the error which was
reported. This certainly never works for attributes.

> Regards
> Ajay

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Re: how to xpath when schema validation fails.

Posted by ajay bhadauria <ab...@yahoo.com>.
Michael,

Thanks for response and explanation.

But can we use current-element-node property which could be set to javax.xml.validation.Validator using setProperty and we get the node which is in error during validation ? Once we get the node and then with getParaentNode recursively and get the complete xpath ?


Regards
Ajay  

--- On Wed, 11/5/08, Michael Glavassevich <mr...@ca.ibm.com> wrote:

> From: Michael Glavassevich <mr...@ca.ibm.com>
> Subject: Re: how to xpath when schema validation fails.
> To: xalan-j-users@xml.apache.org
> Cc: abhadauria@yahoo.com, j-users@xerces.apache.org
> Date: Wednesday, November 5, 2008, 11:22 PM
> Hi Ajay,
> 
> The short answer to your question is no. The DOM API
> provides no methods
> for getting line/column numbers so they're not
> available to the validator
> when DOM is the input. There are some non-standard ways of
> adding
> line/column info to DOM nodes using user data (introduced
> in DOM Level 3).
> There's a sample [1] that ships with Xerces-J that
> shows how you can do it.
> The validator won't read this info but your application
> could read it from
> the current element node [2] when an error is reported.
> Note that if you've
> mutated the DOM after loading it the line/column numbers
> may become
> misleading/meaningless.
> 
> Thanks.
> 
> [1]
> http://xerces.apache.org/xerces2-j/samples-dom.html#DOMAddLines
> [2]
> http://xerces.apache.org/xerces2-j/properties.html#dom.current-element-node
> 
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
> 
> ajay bhadauria <ab...@yahoo.com> wrote on
> 11/04/2008 05:13:27 PM:
> 
> > Michael,
> >
> > Thanks for response. I have gone through all the links
> which you
> > have provided. It looks like that there is no straight
> way to get the
> xpath.
> >
> > If I get the line number during validation error that
> will be great.
> >
> > I know that DOM level 2 does not give line number
> during validation
> error.
> >
> > How can I get the line number when validation error
> takes place ?
> >
> > SAXSource and StreamSource give line number but I want
> only with
> > DOM. So is there any way I can get the line number
> during validation
> > error ? Does DOM level 3 give line number ?
> >
> > Thanks
> > Ajay
> >
> >
> > --- On Fri, 10/31/08, Michael Glavassevich
> <mr...@ca.ibm.com> wrote:
> >
> > > From: Michael Glavassevich
> <mr...@ca.ibm.com>
> > > Subject: Re: how to xpath when schema validation
> fails.
> > > To: abhadauria@yahoo.com
> > > Cc: xalan-j-users@xml.apache.org
> > > Date: Friday, October 31, 2008, 9:34 PM
> > > Hi Ajay,
> > >
> > > There's no reliable way to do that. This
> topic has come
> > > up on the Xerces
> > > mailing list several times. See one of my
> responses here
> > > [1].
> > >
> > > Thanks.
> > >
> > > [1]
> > >
> http://marc.info/?l=xerces-j-user&m=107375672210434&w=2
> > >
> > > Michael Glavassevich
> > > XML Parser Development
> > > IBM Toronto Lab
> > > E-mail: mrglavas@ca.ibm.com
> > > E-mail: mrglavas@apache.org
> > >
> > > ajay bhadauria <ab...@yahoo.com> wrote
> on
> > > 10/31/2008 11:55:59 AM:
> > >
> > > > Hi,
> > > >
> > > > I need help.
> > > >
> > > > I am doing xml document validation against
> schema
> > > using xalan 2.7.1.
> > > > I am providing dom to validate API of xalan
> 2.7.1.
> > > >
> > > > So when dcoument validation fails on some
> element of
> > > the xml
> > > > document , how do we construct xpath from
> root element
> > > of the
> > > > document to the element where error
> occuurred.
> > > >
> > > >
> > > > Thanks a lot.
> > > >
> > > > Ajay Bhadauria


      

Re: how to xpath when schema validation fails.

Posted by ajay bhadauria <ab...@yahoo.com>.
Michael,

Thanks for response and explanation.

But can we use current-element-node property which could be set to javax.xml.validation.Validator using setProperty and we get the node which is in error during validation ? Once we get the node and then with getParaentNode recursively and get the complete xpath ?


Regards
Ajay  

--- On Wed, 11/5/08, Michael Glavassevich <mr...@ca.ibm.com> wrote:

> From: Michael Glavassevich <mr...@ca.ibm.com>
> Subject: Re: how to xpath when schema validation fails.
> To: xalan-j-users@xml.apache.org
> Cc: abhadauria@yahoo.com, j-users@xerces.apache.org
> Date: Wednesday, November 5, 2008, 11:22 PM
> Hi Ajay,
> 
> The short answer to your question is no. The DOM API
> provides no methods
> for getting line/column numbers so they're not
> available to the validator
> when DOM is the input. There are some non-standard ways of
> adding
> line/column info to DOM nodes using user data (introduced
> in DOM Level 3).
> There's a sample [1] that ships with Xerces-J that
> shows how you can do it.
> The validator won't read this info but your application
> could read it from
> the current element node [2] when an error is reported.
> Note that if you've
> mutated the DOM after loading it the line/column numbers
> may become
> misleading/meaningless.
> 
> Thanks.
> 
> [1]
> http://xerces.apache.org/xerces2-j/samples-dom.html#DOMAddLines
> [2]
> http://xerces.apache.org/xerces2-j/properties.html#dom.current-element-node
> 
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
> 
> ajay bhadauria <ab...@yahoo.com> wrote on
> 11/04/2008 05:13:27 PM:
> 
> > Michael,
> >
> > Thanks for response. I have gone through all the links
> which you
> > have provided. It looks like that there is no straight
> way to get the
> xpath.
> >
> > If I get the line number during validation error that
> will be great.
> >
> > I know that DOM level 2 does not give line number
> during validation
> error.
> >
> > How can I get the line number when validation error
> takes place ?
> >
> > SAXSource and StreamSource give line number but I want
> only with
> > DOM. So is there any way I can get the line number
> during validation
> > error ? Does DOM level 3 give line number ?
> >
> > Thanks
> > Ajay
> >
> >
> > --- On Fri, 10/31/08, Michael Glavassevich
> <mr...@ca.ibm.com> wrote:
> >
> > > From: Michael Glavassevich
> <mr...@ca.ibm.com>
> > > Subject: Re: how to xpath when schema validation
> fails.
> > > To: abhadauria@yahoo.com
> > > Cc: xalan-j-users@xml.apache.org
> > > Date: Friday, October 31, 2008, 9:34 PM
> > > Hi Ajay,
> > >
> > > There's no reliable way to do that. This
> topic has come
> > > up on the Xerces
> > > mailing list several times. See one of my
> responses here
> > > [1].
> > >
> > > Thanks.
> > >
> > > [1]
> > >
> http://marc.info/?l=xerces-j-user&m=107375672210434&w=2
> > >
> > > Michael Glavassevich
> > > XML Parser Development
> > > IBM Toronto Lab
> > > E-mail: mrglavas@ca.ibm.com
> > > E-mail: mrglavas@apache.org
> > >
> > > ajay bhadauria <ab...@yahoo.com> wrote
> on
> > > 10/31/2008 11:55:59 AM:
> > >
> > > > Hi,
> > > >
> > > > I need help.
> > > >
> > > > I am doing xml document validation against
> schema
> > > using xalan 2.7.1.
> > > > I am providing dom to validate API of xalan
> 2.7.1.
> > > >
> > > > So when dcoument validation fails on some
> element of
> > > the xml
> > > > document , how do we construct xpath from
> root element
> > > of the
> > > > document to the element where error
> occuurred.
> > > >
> > > >
> > > > Thanks a lot.
> > > >
> > > > Ajay Bhadauria


      

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


Re: how to xpath when schema validation fails.

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Ajay,

The short answer to your question is no. The DOM API provides no methods
for getting line/column numbers so they're not available to the validator
when DOM is the input. There are some non-standard ways of adding
line/column info to DOM nodes using user data (introduced in DOM Level 3).
There's a sample [1] that ships with Xerces-J that shows how you can do it.
The validator won't read this info but your application could read it from
the current element node [2] when an error is reported. Note that if you've
mutated the DOM after loading it the line/column numbers may become
misleading/meaningless.

Thanks.

[1] http://xerces.apache.org/xerces2-j/samples-dom.html#DOMAddLines
[2]
http://xerces.apache.org/xerces2-j/properties.html#dom.current-element-node

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

ajay bhadauria <ab...@yahoo.com> wrote on 11/04/2008 05:13:27 PM:

> Michael,
>
> Thanks for response. I have gone through all the links which you
> have provided. It looks like that there is no straight way to get the
xpath.
>
> If I get the line number during validation error that will be great.
>
> I know that DOM level 2 does not give line number during validation
error.
>
> How can I get the line number when validation error takes place ?
>
> SAXSource and StreamSource give line number but I want only with
> DOM. So is there any way I can get the line number during validation
> error ? Does DOM level 3 give line number ?
>
> Thanks
> Ajay
>
>
> --- On Fri, 10/31/08, Michael Glavassevich <mr...@ca.ibm.com> wrote:
>
> > From: Michael Glavassevich <mr...@ca.ibm.com>
> > Subject: Re: how to xpath when schema validation fails.
> > To: abhadauria@yahoo.com
> > Cc: xalan-j-users@xml.apache.org
> > Date: Friday, October 31, 2008, 9:34 PM
> > Hi Ajay,
> >
> > There's no reliable way to do that. This topic has come
> > up on the Xerces
> > mailing list several times. See one of my responses here
> > [1].
> >
> > Thanks.
> >
> > [1]
> > http://marc.info/?l=xerces-j-user&m=107375672210434&w=2
> >
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: mrglavas@ca.ibm.com
> > E-mail: mrglavas@apache.org
> >
> > ajay bhadauria <ab...@yahoo.com> wrote on
> > 10/31/2008 11:55:59 AM:
> >
> > > Hi,
> > >
> > > I need help.
> > >
> > > I am doing xml document validation against schema
> > using xalan 2.7.1.
> > > I am providing dom to validate API of xalan 2.7.1.
> > >
> > > So when dcoument validation fails on some element of
> > the xml
> > > document , how do we construct xpath from root element
> > of the
> > > document to the element where error occuurred.
> > >
> > >
> > > Thanks a lot.
> > >
> > > Ajay Bhadauria

Re: how to xpath when schema validation fails.

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Ajay,

The short answer to your question is no. The DOM API provides no methods
for getting line/column numbers so they're not available to the validator
when DOM is the input. There are some non-standard ways of adding
line/column info to DOM nodes using user data (introduced in DOM Level 3).
There's a sample [1] that ships with Xerces-J that shows how you can do it.
The validator won't read this info but your application could read it from
the current element node [2] when an error is reported. Note that if you've
mutated the DOM after loading it the line/column numbers may become
misleading/meaningless.

Thanks.

[1] http://xerces.apache.org/xerces2-j/samples-dom.html#DOMAddLines
[2]
http://xerces.apache.org/xerces2-j/properties.html#dom.current-element-node

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

ajay bhadauria <ab...@yahoo.com> wrote on 11/04/2008 05:13:27 PM:

> Michael,
>
> Thanks for response. I have gone through all the links which you
> have provided. It looks like that there is no straight way to get the
xpath.
>
> If I get the line number during validation error that will be great.
>
> I know that DOM level 2 does not give line number during validation
error.
>
> How can I get the line number when validation error takes place ?
>
> SAXSource and StreamSource give line number but I want only with
> DOM. So is there any way I can get the line number during validation
> error ? Does DOM level 3 give line number ?
>
> Thanks
> Ajay
>
>
> --- On Fri, 10/31/08, Michael Glavassevich <mr...@ca.ibm.com> wrote:
>
> > From: Michael Glavassevich <mr...@ca.ibm.com>
> > Subject: Re: how to xpath when schema validation fails.
> > To: abhadauria@yahoo.com
> > Cc: xalan-j-users@xml.apache.org
> > Date: Friday, October 31, 2008, 9:34 PM
> > Hi Ajay,
> >
> > There's no reliable way to do that. This topic has come
> > up on the Xerces
> > mailing list several times. See one of my responses here
> > [1].
> >
> > Thanks.
> >
> > [1]
> > http://marc.info/?l=xerces-j-user&m=107375672210434&w=2
> >
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: mrglavas@ca.ibm.com
> > E-mail: mrglavas@apache.org
> >
> > ajay bhadauria <ab...@yahoo.com> wrote on
> > 10/31/2008 11:55:59 AM:
> >
> > > Hi,
> > >
> > > I need help.
> > >
> > > I am doing xml document validation against schema
> > using xalan 2.7.1.
> > > I am providing dom to validate API of xalan 2.7.1.
> > >
> > > So when dcoument validation fails on some element of
> > the xml
> > > document , how do we construct xpath from root element
> > of the
> > > document to the element where error occuurred.
> > >
> > >
> > > Thanks a lot.
> > >
> > > Ajay Bhadauria

Re: how to xpath when schema validation fails.

Posted by ajay bhadauria <ab...@yahoo.com>.
Michael,

Thanks for response. I have gone through all the links which you have provided. It looks like that there is no straight way to get the xpath.

If I get the line number during validation error that will be great.

I know that DOM level 2 does not give line number during validation error. 

How can I get the line number when validation error takes place ? 

SAXSource and StreamSource give line number but I want only with DOM. So is there any way I can get the line number during validation error ? Does DOM level 3 give line number ?

Thanks
Ajay   


--- On Fri, 10/31/08, Michael Glavassevich <mr...@ca.ibm.com> wrote:

> From: Michael Glavassevich <mr...@ca.ibm.com>
> Subject: Re: how to xpath when schema validation fails.
> To: abhadauria@yahoo.com
> Cc: xalan-j-users@xml.apache.org
> Date: Friday, October 31, 2008, 9:34 PM
> Hi Ajay,
> 
> There's no reliable way to do that. This topic has come
> up on the Xerces
> mailing list several times. See one of my responses here
> [1].
> 
> Thanks.
> 
> [1]
> http://marc.info/?l=xerces-j-user&m=107375672210434&w=2
> 
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
> 
> ajay bhadauria <ab...@yahoo.com> wrote on
> 10/31/2008 11:55:59 AM:
> 
> > Hi,
> >
> > I need help.
> >
> > I am doing xml document validation against schema
> using xalan 2.7.1.
> > I am providing dom to validate API of xalan 2.7.1.
> >
> > So when dcoument validation fails on some element of
> the xml
> > document , how do we construct xpath from root element
> of the
> > document to the element where error occuurred.
> >
> >
> > Thanks a lot.
> >
> > Ajay Bhadauria


      

Re: how to xpath when schema validation fails.

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Ajay,

There's no reliable way to do that. This topic has come up on the Xerces
mailing list several times. See one of my responses here [1].

Thanks.

[1] http://marc.info/?l=xerces-j-user&m=107375672210434&w=2

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

ajay bhadauria <ab...@yahoo.com> wrote on 10/31/2008 11:55:59 AM:

> Hi,
>
> I need help.
>
> I am doing xml document validation against schema using xalan 2.7.1.
> I am providing dom to validate API of xalan 2.7.1.
>
> So when dcoument validation fails on some element of the xml
> document , how do we construct xpath from root element of the
> document to the element where error occuurred.
>
>
> Thanks a lot.
>
> Ajay Bhadauria