Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » How to set focus in org.eclipse.wst.xml.xpath2.processor.jar
How to set focus in org.eclipse.wst.xml.xpath2.processor.jar [message #230404] Wed, 15 April 2009 17:49 Go to next message
Ken Cai is currently offline Ken CaiFriend
Messages: 1
Registered: July 2009
Junior Member
Hi there,

Need some help with the org.eclipse.wst.xml.xpath2.processor.jar API

To evaluate xpath expression, the following code works fine.

is = new FileInputStream("D:\\aFile.xml");
DOMLoader domloader = new XercesLoader();
Document doc = domloader.load(is);
ElementPSVI rootPSVI = (ElementPSVI)doc.getDocumentElement();
XSModel schema = rootPSVI.getSchemaInformation();

DynamicContext dc = new DefaultDynamicContext(schema, doc);
dc.add_function_library(new FnFunctionLibrary());
dc.add_function_library(new XSCtrLibrary());
dc.add_function_library(new XDTCtrLibrary());


String xpath = "Xpath expression";
XPathParser xpp = new JFlexCupParser();
XPath path = xpp.parse(xpath);

StaticChecker name_check = new StaticNameResolver(dc);
name_check.check(path);

Evaluator eval = new DefaultEvaluator(dc, doc);
ResultSequence rs = eval.evaluate(path);

But the context node for evaluation is the DOM Document node. We want the
context to be the top most element (which is required by the XML Schema
1.1 assertions spec).

Use the following code to do this,
// setting the focus to the document element
ElementType psyElement = new ElementType(doc.getDocumentElement(), 0);
Focus contextFocus = new Focus(new DefaultResultSequence(psyElement));
dc.set_focus(contextFocus);

Evaluator eval = new DefaultEvaluator(dc, doc);

but this doesn't work. The 2nd argument to the constructor of
ElementType is an integer, meaning "the document order" (ref,
http://psychopath.sourceforge.net/javadoc/org/ucl/xpath/type s/ElementType.html).

It seems, the org.eclipse.wst.xml.xpath2.processor documentation doesn't
describe what could be the possible values for "document order" integer.
tried with document order values of 0, 1 & -1. but these don't work.

How can we get the top most element?

Thanks in advance,
Ken
Re: How to set focus in org.eclipse.wst.xml.xpath2.processor.jar [message #230502 is a reply to message #230404] Sat, 18 April 2009 17:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dcarver.starstandard.org

Ken you should be able to pass in the starting element where the Xpath
should begin, and then that should set the focus to that element.

I'll take a look later tonight when I get home, and setup a unit test
for this scenario.

If you haven't, please open a bug report and I'll track the progress and
updates there.


Dave

Ken Cai wrote:
> Hi there,
>
> Need some help with the org.eclipse.wst.xml.xpath2.processor.jar API
>
> To evaluate xpath expression, the following code works fine.
>
> is = new FileInputStream("D:\\aFile.xml");
> DOMLoader domloader = new XercesLoader(); Document doc =
> domloader.load(is);
> ElementPSVI rootPSVI = (ElementPSVI)doc.getDocumentElement(); XSModel
> schema = rootPSVI.getSchemaInformation();
> DynamicContext dc = new DefaultDynamicContext(schema, doc);
> dc.add_function_library(new FnFunctionLibrary());
> dc.add_function_library(new XSCtrLibrary());
> dc.add_function_library(new XDTCtrLibrary());
>
> String xpath = "Xpath expression";
> XPathParser xpp = new JFlexCupParser(); XPath path = xpp.parse(xpath);
> StaticChecker name_check = new StaticNameResolver(dc);
> name_check.check(path); Evaluator eval = new
> DefaultEvaluator(dc, doc); ResultSequence rs = eval.evaluate(path);
> But the context node for evaluation is the DOM Document node. We want
> the context to be the top most element (which is required by the XML
> Schema 1.1 assertions spec).
>
> Use the following code to do this, // setting the focus to the document
> element
> ElementType psyElement = new ElementType(doc.getDocumentElement(), 0);
> Focus contextFocus = new Focus(new DefaultResultSequence(psyElement));
> dc.set_focus(contextFocus);
>
> Evaluator eval = new DefaultEvaluator(dc, doc);
>
> but this doesn't work. The 2nd argument to the constructor of
> ElementType is an integer, meaning "the document order" (ref,
> http://psychopath.sourceforge.net/javadoc/org/ucl/xpath/type s/ElementType.html).
>
>
> It seems, the org.eclipse.wst.xml.xpath2.processor documentation doesn't
> describe what could be the possible values for "document order" integer.
> tried with document order values of 0, 1 & -1. but these don't work.
>
> How can we get the top most element?
>
> Thanks in advance,
> Ken
>
>
>
>
Re: How to set focus in org.eclipse.wst.xml.xpath2.processor.jar [message #230510 is a reply to message #230404] Sat, 18 April 2009 17:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dcarver.starstandard.org

Ken, you may need to implement your own implementation of
DefaultEvaluator. That takes in a dom Node and then evaluates from
there instead of using the DefaultEvaluator. Take a look at the
DefaultEvaluator class for an example on how to implement your own
validator class. If you do implement this, please consider
contributing it back and I'll incorporate it into the base package.

So I would have a NodeEvaluator that had a constructor that took (a
DynamicContext implement, and dom DOM).

You can probably extend the DefaultEvaluator class.

Dave

Ken Cai wrote:
> Hi there,
>
> Need some help with the org.eclipse.wst.xml.xpath2.processor.jar API
>
> To evaluate xpath expression, the following code works fine.
>
> is = new FileInputStream("D:\\aFile.xml");
> DOMLoader domloader = new XercesLoader(); Document doc =
> domloader.load(is);
> ElementPSVI rootPSVI = (ElementPSVI)doc.getDocumentElement(); XSModel
> schema = rootPSVI.getSchemaInformation();
> DynamicContext dc = new DefaultDynamicContext(schema, doc);
> dc.add_function_library(new FnFunctionLibrary());
> dc.add_function_library(new XSCtrLibrary());
> dc.add_function_library(new XDTCtrLibrary());
>
> String xpath = "Xpath expression";
> XPathParser xpp = new JFlexCupParser(); XPath path = xpp.parse(xpath);
> StaticChecker name_check = new StaticNameResolver(dc);
> name_check.check(path); Evaluator eval = new
> DefaultEvaluator(dc, doc); ResultSequence rs = eval.evaluate(path);
> But the context node for evaluation is the DOM Document node. We want
> the context to be the top most element (which is required by the XML
> Schema 1.1 assertions spec).
>
> Use the following code to do this, // setting the focus to the document
> element
> ElementType psyElement = new ElementType(doc.getDocumentElement(), 0);
> Focus contextFocus = new Focus(new DefaultResultSequence(psyElement));
> dc.set_focus(contextFocus);
>
> Evaluator eval = new DefaultEvaluator(dc, doc);
>
> but this doesn't work. The 2nd argument to the constructor of
> ElementType is an integer, meaning "the document order" (ref,
> http://psychopath.sourceforge.net/javadoc/org/ucl/xpath/type s/ElementType.html).
>
>
> It seems, the org.eclipse.wst.xml.xpath2.processor documentation doesn't
> describe what could be the possible values for "document order" integer.
> tried with document order values of 0, 1 & -1. but these don't work.
>
> How can we get the top most element?
>
> Thanks in advance,
> Ken
>
>
>
>
Re: How to set focus in org.eclipse.wst.xml.xpath2.processor.jar [message #231852 is a reply to message #230502] Tue, 26 May 2009 03:00 Go to previous message
Eclipse UserFriend
Originally posted by: dcarver.starstandard.org

Ken,

While working on the XPath2 Processor (Psychopath) for the W3C Test
suite, I found another way you can accomplish what you want to do with
out creating your own implementation of a Context. You can use an
XPath variable, and assign your current context node to it. Check the
dc.set_variable() method. It takes a QName, and NodeType to be used.

You can then have your Xpath to execute be:

$variable/somexpath

And it will execute using the value you stored in the variable as the
starting point.

The W3C test suite uses this quite a bit for testing navigation.

Hope this tip helps.

Dave

David Carver wrote:
> Ken you should be able to pass in the starting element where the Xpath
> should begin, and then that should set the focus to that element.
>
> I'll take a look later tonight when I get home, and setup a unit test
> for this scenario.
>
> If you haven't, please open a bug report and I'll track the progress and
> updates there.
>
>
> Dave
>
> Ken Cai wrote:
>> Hi there,
>>
>> Need some help with the org.eclipse.wst.xml.xpath2.processor.jar API
>>
>> To evaluate xpath expression, the following code works fine.
>>
>> is = new FileInputStream("D:\\aFile.xml");
>> DOMLoader domloader = new XercesLoader(); Document doc =
>> domloader.load(is);
>> ElementPSVI rootPSVI = (ElementPSVI)doc.getDocumentElement(); XSModel
>> schema = rootPSVI.getSchemaInformation(); DynamicContext dc = new
>> DefaultDynamicContext(schema, doc); dc.add_function_library(new
>> FnFunctionLibrary());
>> dc.add_function_library(new XSCtrLibrary());
>> dc.add_function_library(new XDTCtrLibrary());
>> String xpath = "Xpath expression";
>> XPathParser xpp = new JFlexCupParser(); XPath path =
>> xpp.parse(xpath); StaticChecker name_check = new
>> StaticNameResolver(dc); name_check.check(path); Evaluator
>> eval = new DefaultEvaluator(dc, doc); ResultSequence rs =
>> eval.evaluate(path); But the context node for evaluation is the
>> DOM Document node. We want the context to be the top most element
>> (which is required by the XML Schema 1.1 assertions spec).
>>
>> Use the following code to do this, // setting the focus to the
>> document element
>> ElementType psyElement = new ElementType(doc.getDocumentElement(), 0);
>> Focus contextFocus = new Focus(new DefaultResultSequence(psyElement));
>> dc.set_focus(contextFocus);
>>
>> Evaluator eval = new DefaultEvaluator(dc, doc);
>>
>> but this doesn't work. The 2nd argument to the constructor of
>> ElementType is an integer, meaning "the document order" (ref,
>> http://psychopath.sourceforge.net/javadoc/org/ucl/xpath/type s/ElementType.html).
>>
>>
>> It seems, the org.eclipse.wst.xml.xpath2.processor documentation
>> doesn't describe what could be the possible values for "document
>> order" integer. tried with document order values of 0, 1 & -1. but
>> these don't work.
>>
>> How can we get the top most element?
>>
>> Thanks in advance,
>> Ken
>>
>>
>>
>>
Previous Topic:text copy/paste background annoying problem
Next Topic:CSS displaying in JavaDoc
Goto Forum:
  


Current Time: Fri Apr 26 08:14:03 GMT 2024

Powered by FUDForum. Page generated in 0.03656 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top