⚲
Project
Profile
Help
Tour this page
Frequent Planio Questions
Learning Resources
Sign in
Register
Switch Planio account
Open in Planio App
Share current page
Search
:
Projects
All Projects
Help
Tour this page
Frequent Planio Questions
Learning Resources
Sign in
Register
Switch Planio account
Open in Planio App
Share current page
Saxon
Overview
Roadmap
Issues
Calendar
Blog
Documents
Forums
Files
Repository
Download (1.27 KB)
Problem with Tracing XPathExpressions
ยป Test.java
Farid Ghanbari
, 2019-03-23 18:50
void
test
()
throws
Exception
{
String
xpath
=
"declare variable $a as item() external; $a/x/text()"
;
Configuration
config
=
Configuration
.
newConfiguration
();
config
.
setCompileWithTracing
(
true
);
Processor
processor
=
new
Processor
(
config
);
XQueryCompiler
xqueryCompiler
=
processor
.
newXQueryCompiler
();
xqueryCompiler
.
setEncoding
(
"UTF-8"
);
xqueryCompiler
.
getUnderlyingStaticContext
()
.
setCodeInjector
(
new
CodeInjector
()
{
@Override
public
Clause
injectClause
(
Clause
target
,
StaticContext
env
)
{
System
.
out
.
println
(
target
);
return
target
;
}
@Override
public
Expression
inject
(
Expression
exp
,
StaticContext
env
,
int
construct
,
StructuredQName
qName
)
{
System
.
out
.
println
(
exp
);
return
exp
;
}
});
XQueryExecutable
xqueryExecutable
=
xqueryCompiler
.
compile
(
xpath
);
XQueryEvaluator
evaluator
=
xqueryExecutable
.
load
();
Source
source
=
new
StreamSource
(
new
StringReader
(
"<a><x>A</x></a>"
));
net
.
sf
.
saxon
.
s9api
.
DocumentBuilder
documentBuilder
=
processor
.
newDocumentBuilder
();
XdmNode
document
=
documentBuilder
.
build
(
source
);
evaluator
.
setExternalVariable
(
new
QName
(
"a"
),
document
.
children
().
iterator
().
next
());
System
.
out
.
println
(
evaluator
.
evaluateSingle
());
}
(1-1/1)
Loading...