You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Venkatesh Prasad Ranganath <vr...@cox.net> on 2003/03/26 14:04:18 UTC

JXPath: XMl traversal

Hi,

The following snippet of code never dives into loop body for the subsequent document.  Can somebody tell me what might I be 
doing wrong?

<doc is a Document object obtained from jaxp parser>
Element root = doc.getDocumentElement();
JXPathContext ctxt = JXPathContext.newContext(root);
for(Iterator i = ctxt.iterate("CONFIGURATION/PROCESSOR"); i.hasNext();) {
	System.out.println("1");
	processProcessor((Element) i.next());
}


<?xml version="1.0" encoding="UTF-8"?>
<!-- DOCTYPE CONFIGURATION SYSTEM "MC__1_1BasicSP.dtd"-->
<!DOCTYPE CONFIGURATION SYSTEM "OEP_Configuration_2_2.dtd">
<CONFIGURATION>
     <PROCESSOR>
         <NAME> PROCESSOR1 </NAME>
     </PROCESSOR>
</CONFIGURATION>

waiting for reply,
-- 

Venkatesh Prasad Ranganath,
Dept. Computing and Information Science,
Kansas State University, US.
web: http://www.cis.ksu.edu/~rvprasad


Re: JXPath: XMl traversal

Posted by Venkatesh Prasad Ranganath <vr...@cox.net>.
Venkatesh Prasad Ranganath wrote:
> Dmitri Plotnikov wrote:
> 
>> Venkatesh,
>>
>> Try passing to the JXPathContext the document itself, rather than its 
>> root
>> element.  I believe JXPath is trying to find a child of the root element
>> called "CONFIGURATION", but of course fails to find one.
>>
>> I hope this helps.
> 
> 
> Nope.  I tried passing the document.  I also tried giving the root 
> element and "//PROCESSOR" as the xpath expression.  Both had no result 
> as in the previous case.  Any clues?
> 

Well, sorry for the mispost.  There was a class version issue and things are resolved now.  However,

context.getValue("INTERVAL_TIMEOUT") != null
throws an exception rather than returning null as there may be no element with tag name "INTERVAL_TIMEOUT".  I have tried 
getPointer() with the same effect.  Any clues why this might occur?  It is my understanding that one can test for optional 
elements by providing an xpath expression and if that evaluates to null then one can conclude that the element does not 
exists.  Is this correct?  If not, how should one test for existence of optional elements?

waiting for reply,

>>
>> - Dmitri Plotnikov
>>
>> ----- Original Message -----
>> From: "Venkatesh Prasad Ranganath" <vr...@cox.net>
>> To: <co...@jakarta.apache.org>
>> Sent: Wednesday, March 26, 2003 8:04 AM
>> Subject: JXPath: XMl traversal
>>
>>
>>
>>> Hi,
>>>
>>> The following snippet of code never dives into loop body for the
>>
>>
>> subsequent document.  Can somebody tell me what might I be
>>
>>> doing wrong?
>>>
>>> <doc is a Document object obtained from jaxp parser>
>>> Element root = doc.getDocumentElement();
>>> JXPathContext ctxt = JXPathContext.newContext(root);
>>> for(Iterator i = ctxt.iterate("CONFIGURATION/PROCESSOR"); 
>>> i.hasNext();) {
>>> System.out.println("1");
>>> processProcessor((Element) i.next());
>>> }
>>>
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <!-- DOCTYPE CONFIGURATION SYSTEM "MC__1_1BasicSP.dtd"-->
>>> <!DOCTYPE CONFIGURATION SYSTEM "OEP_Configuration_2_2.dtd">
>>> <CONFIGURATION>
>>>     <PROCESSOR>
>>>         <NAME> PROCESSOR1 </NAME>
>>>     </PROCESSOR>
>>> </CONFIGURATION>
>>>
>>> waiting for reply,
>>> -- 
>>>
>>> Venkatesh Prasad Ranganath,
>>> Dept. Computing and Information Science,
>>> Kansas State University, US.
>>> web: http://www.cis.ksu.edu/~rvprasad
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
> 
> 


-- 

Venkatesh Prasad Ranganath,
Dept. Computing and Information Science,
Kansas State University, US.
web: http://www.cis.ksu.edu/~rvprasad


Re: JXPath: XMl traversal

Posted by Venkatesh Prasad Ranganath <vr...@cox.net>.
Venkatesh Prasad Ranganath wrote:
> Dmitri Plotnikov wrote:
> 
>> Venkatesh,
>>
>> Try passing to the JXPathContext the document itself, rather than its 
>> root
>> element.  I believe JXPath is trying to find a child of the root element
>> called "CONFIGURATION", but of course fails to find one.
>>
>> I hope this helps.
> 
> 
> Nope.  I tried passing the document.  I also tried giving the root 
> element and "//PROCESSOR" as the xpath expression.  Both had no result 
> as in the previous case.  Any clues?
> 

Don't mind my previoud post.  I figured out the "leniency" issue.

>>
>> - Dmitri Plotnikov
>>
>> ----- Original Message -----
>> From: "Venkatesh Prasad Ranganath" <vr...@cox.net>
>> To: <co...@jakarta.apache.org>
>> Sent: Wednesday, March 26, 2003 8:04 AM
>> Subject: JXPath: XMl traversal
>>
>>
>>
>>> Hi,
>>>
>>> The following snippet of code never dives into loop body for the
>>
>>
>> subsequent document.  Can somebody tell me what might I be
>>
>>> doing wrong?
>>>
>>> <doc is a Document object obtained from jaxp parser>
>>> Element root = doc.getDocumentElement();
>>> JXPathContext ctxt = JXPathContext.newContext(root);
>>> for(Iterator i = ctxt.iterate("CONFIGURATION/PROCESSOR"); 
>>> i.hasNext();) {
>>> System.out.println("1");
>>> processProcessor((Element) i.next());
>>> }
>>>
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <!-- DOCTYPE CONFIGURATION SYSTEM "MC__1_1BasicSP.dtd"-->
>>> <!DOCTYPE CONFIGURATION SYSTEM "OEP_Configuration_2_2.dtd">
>>> <CONFIGURATION>
>>>     <PROCESSOR>
>>>         <NAME> PROCESSOR1 </NAME>
>>>     </PROCESSOR>
>>> </CONFIGURATION>
>>>
>>> waiting for reply,
>>> -- 
>>>
>>> Venkatesh Prasad Ranganath,
>>> Dept. Computing and Information Science,
>>> Kansas State University, US.
>>> web: http://www.cis.ksu.edu/~rvprasad
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
> 
> 


-- 

Venkatesh Prasad Ranganath,
Dept. Computing and Information Science,
Kansas State University, US.
web: http://www.cis.ksu.edu/~rvprasad


Re: JXPath: XMl traversal

Posted by Venkatesh Prasad Ranganath <vr...@cox.net>.
Dmitri Plotnikov wrote:
> Venkatesh,
> 
> Try passing to the JXPathContext the document itself, rather than its root
> element.  I believe JXPath is trying to find a child of the root element
> called "CONFIGURATION", but of course fails to find one.
> 
> I hope this helps.

Nope.  I tried passing the document.  I also tried giving the root element and "//PROCESSOR" as the xpath expression.  Both 
had no result as in the previous case.  Any clues?

> 
> - Dmitri Plotnikov
> 
> ----- Original Message -----
> From: "Venkatesh Prasad Ranganath" <vr...@cox.net>
> To: <co...@jakarta.apache.org>
> Sent: Wednesday, March 26, 2003 8:04 AM
> Subject: JXPath: XMl traversal
> 
> 
> 
>>Hi,
>>
>>The following snippet of code never dives into loop body for the
> 
> subsequent document.  Can somebody tell me what might I be
> 
>>doing wrong?
>>
>><doc is a Document object obtained from jaxp parser>
>>Element root = doc.getDocumentElement();
>>JXPathContext ctxt = JXPathContext.newContext(root);
>>for(Iterator i = ctxt.iterate("CONFIGURATION/PROCESSOR"); i.hasNext();) {
>>System.out.println("1");
>>processProcessor((Element) i.next());
>>}
>>
>>
>><?xml version="1.0" encoding="UTF-8"?>
>><!-- DOCTYPE CONFIGURATION SYSTEM "MC__1_1BasicSP.dtd"-->
>><!DOCTYPE CONFIGURATION SYSTEM "OEP_Configuration_2_2.dtd">
>><CONFIGURATION>
>>     <PROCESSOR>
>>         <NAME> PROCESSOR1 </NAME>
>>     </PROCESSOR>
>></CONFIGURATION>
>>
>>waiting for reply,
>>--
>>
>>Venkatesh Prasad Ranganath,
>>Dept. Computing and Information Science,
>>Kansas State University, US.
>>web: http://www.cis.ksu.edu/~rvprasad
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>>
>>
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


-- 

Venkatesh Prasad Ranganath,
Dept. Computing and Information Science,
Kansas State University, US.
web: http://www.cis.ksu.edu/~rvprasad


Re: JXPath: XMl traversal

Posted by Dmitri Plotnikov <dm...@apache.org>.
Venkatesh,

Try passing to the JXPathContext the document itself, rather than its root
element.  I believe JXPath is trying to find a child of the root element
called "CONFIGURATION", but of course fails to find one.

I hope this helps.

- Dmitri Plotnikov

----- Original Message -----
From: "Venkatesh Prasad Ranganath" <vr...@cox.net>
To: <co...@jakarta.apache.org>
Sent: Wednesday, March 26, 2003 8:04 AM
Subject: JXPath: XMl traversal


> Hi,
>
> The following snippet of code never dives into loop body for the
subsequent document.  Can somebody tell me what might I be
> doing wrong?
>
> <doc is a Document object obtained from jaxp parser>
> Element root = doc.getDocumentElement();
> JXPathContext ctxt = JXPathContext.newContext(root);
> for(Iterator i = ctxt.iterate("CONFIGURATION/PROCESSOR"); i.hasNext();) {
> System.out.println("1");
> processProcessor((Element) i.next());
> }
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!-- DOCTYPE CONFIGURATION SYSTEM "MC__1_1BasicSP.dtd"-->
> <!DOCTYPE CONFIGURATION SYSTEM "OEP_Configuration_2_2.dtd">
> <CONFIGURATION>
>      <PROCESSOR>
>          <NAME> PROCESSOR1 </NAME>
>      </PROCESSOR>
> </CONFIGURATION>
>
> waiting for reply,
> --
>
> Venkatesh Prasad Ranganath,
> Dept. Computing and Information Science,
> Kansas State University, US.
> web: http://www.cis.ksu.edu/~rvprasad
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>