You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Ragunath Marudhachalam <rm...@circuitvision.com> on 2003/05/12 21:53:06 UTC

How to get the full parent child path on schema validation.

Hello All,

I have been able to validate a xml document with a schema.  I do have the
handler class and i'm able to print the error messages and also the line
number where the error has occured. For some reasons i need to have the
whole tree structure of the element where the error has occured. For
example, if the xml document is like this,

<a>
	<b>
		<c>
			<d>
			</d>

		</c>

	</b>

</a>

and the error is at the element <d>, then i need to get the whole tree
structure from the root element, like a/b/c/d.... is it possible to get that
in someway.. As far as i know, i havent found a direct method to do
that...It would be a real help if anybody could suggest me some method or
with some sample code....

Thanks

Ragu
CircuitVision



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


RE: How to get the full parent child path on schema validation.

Posted by Ragunath Marudhachalam <rm...@circuitvision.com>.
Hi Rahul, Ron, Venu,

Thank you all for your kind help. I set the feature, and using that
property, i am able to get the whole tree structure. This is a long time
problem i had and its been fixed now. Once again thank u guys for ur time
and help.



Ragu
CircuitVision



-----Original Message-----
From: K. Venugopal [mailto:k.venugopal@sun.com]
Sent: Wednesday, May 14, 2003 6:19 AM
To: xerces-j-user@xml.apache.org
Subject: Re: How to get the full parent child path on schema validation.


Hi Ragu,

In addition to what rahul mentioned i think you need to set the
following feature to false .
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion"
,false);

Regards
venu

Rahul Srivastava wrote:

> > Ragunath Marudhachalam wrote...
> >
> > Hi Rahul,
> >
> > Thanks for the tip. I'm using DOM Parser. I went thru the link u gave
me,
> > but i didnt get to know how to use it. I mean to set the
> > property, and how to get the element name.
>
>If you have read the docs, you will notice that the property
>current-element-node is readonly. You cannot set this property. To use this
>property, register an ErrorHandler with the DOM parser. Within the callback
>of the registered ErrorHandler, you need to do something like this:
>Element node =
>(Element)parser.getProperty("http://apache.org/xml/properties/dom/current-e
l
>ement-node");
>if (node != null) {
>    // now you have the node from where you can
>    // traverse all the way back to the root
>    System.out.println(node.getNodeName());
>    System.out.println(node.getParentNode().getNodeName());
>}
>
>Hope that helps.
>
>Cheers,
>Rahul.
>
>
>
> > If you dont mind, could u plz help me
> > as how to use
> > it or give me a small sample of how to use it, coz so far i have
> > only used
> > setting features. I am very thankful for your time and help.
> >
> > Ragu
> > CircuitVision
> >
> >
> >
> > -----Original Message-----
> > From: Rahul Srivastava [mailto:rsrivastava@firstam.com]
> > Sent: Tuesday, May 13, 2003 2:14 AM
> > To: xerces-j-user@xml.apache.org
> > Subject: RE: How to get the full parent child path on schema validation.
> >
> >
> > Hi Ragu,
> >
> > You did not mention which parsing are you using viz. SAX/DOM parsing!.
> >
> > In case you are using DOM parsing, you can try using the property
> > dom/current-element-node, which will give you the current node.
> > You can then
> > traverse back from that node and get the full tree.
> > See:
> > http://xml.apache.org/xerces2-j/properties.html#dom.current-element-node
> > for more details.
> >
> > Cheers,
> > Rahul.
> >
> >
> >
> >  > Ragunath Marudhachalam wrote...
> >  >
> >  > Hello All,
> >  >
> >  > I have been able to validate a xml document with a schema.  I
> > do have the
> >  > handler class and i'm able to print the error messages and
> > also the line
> >  > number where the error has occured. For some reasons i need
> > to have the
> >  > whole tree structure of the element where the error has occured. For
> >  > example, if the xml document is like this,
> >  >
> >  > <a>
> >  > 	<b>
> >  > 		<c>
> >  > 			<d>
> >  > 			</d>
> >  >
> >  > 		</c>
> >  >
> >  > 	</b>
> >  >
> >  > </a>
> >  >
> >  > and the error is at the element <d>, then i need to get the whole
tree
> >  > structure from the root element, like a/b/c/d.... is it possible
> >  > to get that
> >  > in someway.. As far as i know, i havent found a direct method to do
> >  > that...It would be a real help if anybody could suggest me
> > some method or
> >  > with some sample code....
> >  >
> >  > Thanks
> >  >
> >  > Ragu
> >  > CircuitVision
> >  >
> >  >
> >  >
> >  > ---------------------------------------------------------------------
> >  > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> >  > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> >  >
> >  >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> >
> >
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>
>



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


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


RE: How to get the full parent child path on schema validation.

Posted by Rahul Srivastava <rs...@firstam.com>.
 > K. Venugopal wrote...
 >
 > In addition to what rahul mentioned i think you need to set the
 > following feature to false .
 > parser.setFeature("http://apache.org/xml/features/dom/defer-node-
 > expansion"
 > ,false);

That's right Venu. Thanks for pointing it out.

-Rahul.



 >
 > Regards
 > venu
 >
 > Rahul Srivastava wrote:
 >
 > > > Ragunath Marudhachalam wrote...
 > > >
 > > > Hi Rahul,
 > > >
 > > > Thanks for the tip. I'm using DOM Parser. I went thru the
 > link u gave me,
 > > > but i didnt get to know how to use it. I mean to set the
 > > > property, and how to get the element name.
 > >
 > >If you have read the docs, you will notice that the property
 > >current-element-node is readonly. You cannot set this property.
 > To use this
 > >property, register an ErrorHandler with the DOM parser. Within
 > the callback
 > >of the registered ErrorHandler, you need to do something like this:
 > >Element node =
 > >(Element)parser.getProperty("http://apache.org/xml/properties/do
 > m/current-el
 > >ement-node");
 > >if (node != null) {
 > >    // now you have the node from where you can
 > >    // traverse all the way back to the root
 > >    System.out.println(node.getNodeName());
 > >    System.out.println(node.getParentNode().getNodeName());
 > >}
 > >
 > >Hope that helps.
 > >
 > >Cheers,
 > >Rahul.
 > >
 > >
 > >
 > > > If you dont mind, could u plz help me
 > > > as how to use
 > > > it or give me a small sample of how to use it, coz so far i have
 > > > only used
 > > > setting features. I am very thankful for your time and help.
 > > >
 > > > Ragu
 > > > CircuitVision
 > > >
 > > >
 > > >
 > > > -----Original Message-----
 > > > From: Rahul Srivastava [mailto:rsrivastava@firstam.com]
 > > > Sent: Tuesday, May 13, 2003 2:14 AM
 > > > To: xerces-j-user@xml.apache.org
 > > > Subject: RE: How to get the full parent child path on schema
 > validation.
 > > >
 > > >
 > > > Hi Ragu,
 > > >
 > > > You did not mention which parsing are you using viz. SAX/DOM
 > parsing!.
 > > >
 > > > In case you are using DOM parsing, you can try using the property
 > > > dom/current-element-node, which will give you the current node.
 > > > You can then
 > > > traverse back from that node and get the full tree.
 > > > See:
 > > >
 > http://xml.apache.org/xerces2-j/properties.html#dom.current-element-node
 > > > for more details.
 > > >
 > > > Cheers,
 > > > Rahul.
 > > >
 > > >
 > > >
 > > >  > Ragunath Marudhachalam wrote...
 > > >  >
 > > >  > Hello All,
 > > >  >
 > > >  > I have been able to validate a xml document with a schema.  I
 > > > do have the
 > > >  > handler class and i'm able to print the error messages and
 > > > also the line
 > > >  > number where the error has occured. For some reasons i need
 > > > to have the
 > > >  > whole tree structure of the element where the error has
 > occured. For
 > > >  > example, if the xml document is like this,
 > > >  >
 > > >  > <a>
 > > >  > 	<b>
 > > >  > 		<c>
 > > >  > 			<d>
 > > >  > 			</d>
 > > >  >
 > > >  > 		</c>
 > > >  >
 > > >  > 	</b>
 > > >  >
 > > >  > </a>
 > > >  >
 > > >  > and the error is at the element <d>, then i need to get
 > the whole tree
 > > >  > structure from the root element, like a/b/c/d.... is it possible
 > > >  > to get that
 > > >  > in someway.. As far as i know, i havent found a direct
 > method to do
 > > >  > that...It would be a real help if anybody could suggest me
 > > > some method or
 > > >  > with some sample code....
 > > >  >
 > > >  > Thanks
 > > >  >
 > > >  > Ragu
 > > >  > CircuitVision
 > > >  >
 > > >  >
 > > >  >
 > > >  >
 > ---------------------------------------------------------------------
 > > >  > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
 > > >  > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
 > > >  >
 > > >  >
 > > >
 > > >
 > > >
 > > > ---------------------------------------------------------------------
 > > > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
 > > > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
 > > >
 > > >
 > > > ---------------------------------------------------------------------
 > > > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
 > > > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
 > > >
 > > >
 > >
 > >
 > >
 > >---------------------------------------------------------------------
 > >To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
 > >For additional commands, e-mail: xerces-j-user-help@xml.apache.org
 > >
 > >
 > >
 >
 >
 >
 > ---------------------------------------------------------------------
 > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
 > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
 >
 >



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


Re: How to get the full parent child path on schema validation.

Posted by "K. Venugopal" <k....@sun.com>.
Hi Ragu,

In addition to what rahul mentioned i think you need to set the 
following feature to false .
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion" 
,false);

Regards
venu

Rahul Srivastava wrote:

> > Ragunath Marudhachalam wrote...
> >
> > Hi Rahul,
> >
> > Thanks for the tip. I'm using DOM Parser. I went thru the link u gave me,
> > but i didnt get to know how to use it. I mean to set the
> > property, and how to get the element name.
>
>If you have read the docs, you will notice that the property
>current-element-node is readonly. You cannot set this property. To use this
>property, register an ErrorHandler with the DOM parser. Within the callback
>of the registered ErrorHandler, you need to do something like this:
>Element node =
>(Element)parser.getProperty("http://apache.org/xml/properties/dom/current-el
>ement-node");
>if (node != null) {
>    // now you have the node from where you can
>    // traverse all the way back to the root
>    System.out.println(node.getNodeName());
>    System.out.println(node.getParentNode().getNodeName());
>}
>
>Hope that helps.
>
>Cheers,
>Rahul.
>
>
>
> > If you dont mind, could u plz help me
> > as how to use
> > it or give me a small sample of how to use it, coz so far i have
> > only used
> > setting features. I am very thankful for your time and help.
> >
> > Ragu
> > CircuitVision
> >
> >
> >
> > -----Original Message-----
> > From: Rahul Srivastava [mailto:rsrivastava@firstam.com]
> > Sent: Tuesday, May 13, 2003 2:14 AM
> > To: xerces-j-user@xml.apache.org
> > Subject: RE: How to get the full parent child path on schema validation.
> >
> >
> > Hi Ragu,
> >
> > You did not mention which parsing are you using viz. SAX/DOM parsing!.
> >
> > In case you are using DOM parsing, you can try using the property
> > dom/current-element-node, which will give you the current node.
> > You can then
> > traverse back from that node and get the full tree.
> > See:
> > http://xml.apache.org/xerces2-j/properties.html#dom.current-element-node
> > for more details.
> >
> > Cheers,
> > Rahul.
> >
> >
> >
> >  > Ragunath Marudhachalam wrote...
> >  >
> >  > Hello All,
> >  >
> >  > I have been able to validate a xml document with a schema.  I
> > do have the
> >  > handler class and i'm able to print the error messages and
> > also the line
> >  > number where the error has occured. For some reasons i need
> > to have the
> >  > whole tree structure of the element where the error has occured. For
> >  > example, if the xml document is like this,
> >  >
> >  > <a>
> >  > 	<b>
> >  > 		<c>
> >  > 			<d>
> >  > 			</d>
> >  >
> >  > 		</c>
> >  >
> >  > 	</b>
> >  >
> >  > </a>
> >  >
> >  > and the error is at the element <d>, then i need to get the whole tree
> >  > structure from the root element, like a/b/c/d.... is it possible
> >  > to get that
> >  > in someway.. As far as i know, i havent found a direct method to do
> >  > that...It would be a real help if anybody could suggest me
> > some method or
> >  > with some sample code....
> >  >
> >  > Thanks
> >  >
> >  > Ragu
> >  > CircuitVision
> >  >
> >  >
> >  >
> >  > ---------------------------------------------------------------------
> >  > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> >  > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> >  >
> >  >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
> >
> >
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
>For additional commands, e-mail: xerces-j-user-help@xml.apache.org
>
>  
>



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


RE: How to get the full parent child path on schema validation.

Posted by Rahul Srivastava <rs...@firstam.com>.
 > Ragunath Marudhachalam wrote...
 >
 > Hi Rahul,
 >
 > Thanks for the tip. I'm using DOM Parser. I went thru the link u gave me,
 > but i didnt get to know how to use it. I mean to set the
 > property, and how to get the element name.

If you have read the docs, you will notice that the property
current-element-node is readonly. You cannot set this property. To use this
property, register an ErrorHandler with the DOM parser. Within the callback
of the registered ErrorHandler, you need to do something like this:
Element node =
(Element)parser.getProperty("http://apache.org/xml/properties/dom/current-el
ement-node");
if (node != null) {
    // now you have the node from where you can
    // traverse all the way back to the root
    System.out.println(node.getNodeName());
    System.out.println(node.getParentNode().getNodeName());
}

Hope that helps.

Cheers,
Rahul.



 > If you dont mind, could u plz help me
 > as how to use
 > it or give me a small sample of how to use it, coz so far i have
 > only used
 > setting features. I am very thankful for your time and help.
 >
 > Ragu
 > CircuitVision
 >
 >
 >
 > -----Original Message-----
 > From: Rahul Srivastava [mailto:rsrivastava@firstam.com]
 > Sent: Tuesday, May 13, 2003 2:14 AM
 > To: xerces-j-user@xml.apache.org
 > Subject: RE: How to get the full parent child path on schema validation.
 >
 >
 > Hi Ragu,
 >
 > You did not mention which parsing are you using viz. SAX/DOM parsing!.
 >
 > In case you are using DOM parsing, you can try using the property
 > dom/current-element-node, which will give you the current node.
 > You can then
 > traverse back from that node and get the full tree.
 > See:
 > http://xml.apache.org/xerces2-j/properties.html#dom.current-element-node
 > for more details.
 >
 > Cheers,
 > Rahul.
 >
 >
 >
 >  > Ragunath Marudhachalam wrote...
 >  >
 >  > Hello All,
 >  >
 >  > I have been able to validate a xml document with a schema.  I
 > do have the
 >  > handler class and i'm able to print the error messages and
 > also the line
 >  > number where the error has occured. For some reasons i need
 > to have the
 >  > whole tree structure of the element where the error has occured. For
 >  > example, if the xml document is like this,
 >  >
 >  > <a>
 >  > 	<b>
 >  > 		<c>
 >  > 			<d>
 >  > 			</d>
 >  >
 >  > 		</c>
 >  >
 >  > 	</b>
 >  >
 >  > </a>
 >  >
 >  > and the error is at the element <d>, then i need to get the whole tree
 >  > structure from the root element, like a/b/c/d.... is it possible
 >  > to get that
 >  > in someway.. As far as i know, i havent found a direct method to do
 >  > that...It would be a real help if anybody could suggest me
 > some method or
 >  > with some sample code....
 >  >
 >  > Thanks
 >  >
 >  > Ragu
 >  > CircuitVision
 >  >
 >  >
 >  >
 >  > ---------------------------------------------------------------------
 >  > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
 >  > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
 >  >
 >  >
 >
 >
 >
 > ---------------------------------------------------------------------
 > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
 > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
 >
 >
 > ---------------------------------------------------------------------
 > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
 > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
 >
 >



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


RE: How to get the full parent child path on schema validation.

Posted by Ron Rothblum <RO...@il.ibm.com>.
What was suggested (As I understand it) is that you override the
startElement() method of the DOMParser and then your method you call
this.getProperty(CURRENT_ELEMENT) but I'm not sure this is what you need.
Basically you have a node and want to know it's path, so why not use
node.parentNode() until you get to the document element?

Ron Rothblum.


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


RE: How to get the full parent child path on schema validation.

Posted by Ragunath Marudhachalam <rm...@circuitvision.com>.
Hi Rahul,

Thanks for the tip. I'm using DOM Parser. I went thru the link u gave me,
but i didnt get to know how to use it. I mean to set the property, and how
to get the element name. If you dont mind, could u plz help me as how to use
it or give me a small sample of how to use it, coz so far i have only used
setting features. I am very thankful for your time and help.

Ragu
CircuitVision



-----Original Message-----
From: Rahul Srivastava [mailto:rsrivastava@firstam.com]
Sent: Tuesday, May 13, 2003 2:14 AM
To: xerces-j-user@xml.apache.org
Subject: RE: How to get the full parent child path on schema validation.


Hi Ragu,

You did not mention which parsing are you using viz. SAX/DOM parsing!.

In case you are using DOM parsing, you can try using the property
dom/current-element-node, which will give you the current node. You can then
traverse back from that node and get the full tree.
See:
http://xml.apache.org/xerces2-j/properties.html#dom.current-element-node
for more details.

Cheers,
Rahul.



 > Ragunath Marudhachalam wrote...
 >
 > Hello All,
 >
 > I have been able to validate a xml document with a schema.  I do have the
 > handler class and i'm able to print the error messages and also the line
 > number where the error has occured. For some reasons i need to have the
 > whole tree structure of the element where the error has occured. For
 > example, if the xml document is like this,
 >
 > <a>
 > 	<b>
 > 		<c>
 > 			<d>
 > 			</d>
 >
 > 		</c>
 >
 > 	</b>
 >
 > </a>
 >
 > and the error is at the element <d>, then i need to get the whole tree
 > structure from the root element, like a/b/c/d.... is it possible
 > to get that
 > in someway.. As far as i know, i havent found a direct method to do
 > that...It would be a real help if anybody could suggest me some method or
 > with some sample code....
 >
 > Thanks
 >
 > Ragu
 > CircuitVision
 >
 >
 >
 > ---------------------------------------------------------------------
 > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
 > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
 >
 >



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


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


RE: How to get the full parent child path on schema validation.

Posted by Rahul Srivastava <rs...@firstam.com>.
Hi Ragu,

You did not mention which parsing are you using viz. SAX/DOM parsing!.

In case you are using DOM parsing, you can try using the property
dom/current-element-node, which will give you the current node. You can then
traverse back from that node and get the full tree.
See:
http://xml.apache.org/xerces2-j/properties.html#dom.current-element-node
for more details.

Cheers,
Rahul.



 > Ragunath Marudhachalam wrote...
 >
 > Hello All,
 >
 > I have been able to validate a xml document with a schema.  I do have the
 > handler class and i'm able to print the error messages and also the line
 > number where the error has occured. For some reasons i need to have the
 > whole tree structure of the element where the error has occured. For
 > example, if the xml document is like this,
 >
 > <a>
 > 	<b>
 > 		<c>
 > 			<d>
 > 			</d>
 >
 > 		</c>
 >
 > 	</b>
 >
 > </a>
 >
 > and the error is at the element <d>, then i need to get the whole tree
 > structure from the root element, like a/b/c/d.... is it possible
 > to get that
 > in someway.. As far as i know, i havent found a direct method to do
 > that...It would be a real help if anybody could suggest me some method or
 > with some sample code....
 >
 > Thanks
 >
 > Ragu
 > CircuitVision
 >
 >
 >
 > ---------------------------------------------------------------------
 > To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
 > For additional commands, e-mail: xerces-j-user-help@xml.apache.org
 >
 >



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