evaluating xpath 1.0 expressions with Saxon-HE 9.6.0-6 - xpath

My project was using Saxon 9.0.0.2. I am trying to upgrade to Saxon-HE 9.6.0-6.
XPathEvaluator#setBackwardsCompatible(boolean)
this method no longer exists in 9.6.0-6.
I commented that line in my code, but when running i am getting following error:
net.sf.saxon.trans.XPathException: A sequence of more than one item is not allowed as the first argument of name() (<xs:element/>, <xs:element/>, ...)
at net.sf.saxon.expr.Expression.typeError(Expression.java:1123)
at net.sf.saxon.expr.CardinalityChecker.evaluateItem(CardinalityChecker.java:295)
at net.sf.saxon.functions.NameFn.evaluateItem(NameFn.java:52)
at net.sf.saxon.functions.NameFn.evaluateItem(NameFn.java:23)
at net.sf.saxon.expr.Expression.iterate(Expression.java:448)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:192)
at net.sf.saxon.xpath.XPathEvaluator.evaluate(XPathEvaluator.java:239)
at jlibs.examples.xml.sax.dog.engines.SaxonEngine.evaluate(SaxonEngine.java:72)
at jlibs.examples.xml.sax.dog.TestCase.usingDOM(TestCase.java:71)
at jlibs.examples.xml.sax.dog.tests.XPathConformanceTest.run(XPathConformanceTest.java:44)
at jlibs.examples.xml.sax.dog.tests.XPathConformanceTest.main(XPathConformanceTest.java:73)
looks like, if name function throws this when the argument contains sequence of more than one element.
it used to work perfectly fine.
How to make it work without changing my xpaths.

Saxon now offers two APIs for XPath evaluation: the JAXP API and the s9api API. Saxon's implementation of the JAXP API has moved towards conforming as closely as possible with the JAXP specification, including dropping of extensions like the setBackwardsCompatible() method. However, XPathEvaluator allows you to access the StaticContext using getStaticContext(), and this has an option setBackwardsCompatibilityMode() which should restore the old behaviour.
Alternatively, there is also a method setBackwardsCompatible() on the s9api XPathCompiler class.
If you want to take advantage of XPath 2.0, you will probably want to move to the s9api interface, as JAXP has no support for the richer type system of XPath 2.0.

Related

java protobuf3 what is `buildPartial` used for?

As described in this document(https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/Message.Builder.html#buildPartial--) Like MessageLite.Builder.build(), but does not throw an exception if the message is missing required fields. Instead, a partial message is returned
I guess that's a legacy API from proto2? since required keyword is removed in proto3, but they're not marking this API as deprecated, then in which case we should use this?
This allows to easily supply class instance to the unit test environment. Allowing to avoid complex mocking/class construction.

Search methods in FHIR

I'm working on extracting patients info in FHIR server however, I've came across two types of searching methods that were somewhat different. What is the difference between the search method of
Bundle bundle = client.seach().forResource(DiagnosticReport.class)
.
.
and
GET [base]/DiagnosticReport?result.code-value-
quantity=http://loinc.org|2823-3$gt5.4|http://unitsofmeasure.org|mmol/L
It's very confusing as it seemed that there isn't much that is mentioned about these two search methods. Can i achieve the same level of filtering with the first method compared to the url method?
The first is how to perform a search using the Java reference implementation. The latter explains what the actual HTTP query looks like that hits the server (and also specifies some additional search criteria). Behind the scenes the Java code in the first example is actually making an HTTP call that looks similar to the second example. The primary documentation in the FHIR specification deals with the HTTP call. The reference implementations work differently based on which language they are and are documented outside the FHIR specification on a reference implementation by reference implementation basis.

Can not get number of xml nodes from document using spring integration

I am attempting to get the count of the //Root/Record elements using spring integrations int-xml:xpath-header-enricher. It comes back zero regardless of the document passed in.
You have to configure your XPath expression like this:
<int-xml:xpath-expression id="countExpression" expression="count(//ns:Ephemeris/ns:Record)"
ns-prefix="ns"
ns-uri="http://www.sandia.gov/pgmm/Ephemeris"/>
And have it as a reference from the <int-xml:header> instead.
The problem is that your root element in the XML comes with the xmlns="http://www.sandia.gov/pgmm/Ephemeris", so, there is no other way unless we honor namespaces in your source XML. For this purpose we introduce artificial prefix, even if your source XML does have then. We need that in XPath to properly distinguish elements based on some namespace.
I think default DocumentBuilderFactory just doesn't honor namespaces making your possible XPath expressions much horrible when it comes to several namespaces support.

Freemarker What is the advantage of using TemplateMethodModelEx over TemplateMethodModel

Recently we upgraded to Freemarker 2.3.22. We have implemented TemplateMethodModel interface mutliple times in our product. Now we are getting warnings that TemplateMethodModel is deprecated and consider using TemplateMethodModelEx.
Are there any specific things that can be done using TemplateMethodModelEx only?
The advantage of TemplateMethodModelEx is that it accepts non-String method arguments. TemplateMethodModel has remained from the old times (1.x?) when FreeMarker only had string values.

Implementing a DSL in Ruby for generating domain specific XML

I'd like to implement a DSL in Ruby for generating domain specific XML documents (i.e. XML which conforms to a specific schema). I can use e.g. Builder to write the XML in Ruby, which is already a great improvement on writing the XML manually, but I'd also like:
convenience methods that would generate a whole bunch of XML for me
and possibly a way to restrict the generator to a schema (not necessarily an XSD or a DTD, but the implementation could possibly generate only certain tags)
So my plan at the moment is to extend Builder with the convenience methods and ignore the schema restriction side of things for now.
My questions to the community are does this sounds like a reasonable plan, and more importantly, are there any DSLs out there that extend Builder in some fashion that I could use for inspiration.
Unfortunately googling for ruby, xml, builder, extend, dsl, ... doesn't return very interesting results.
I don't know if it uses Builder, but haml is certainly worth looking.
I also found this article wich mentions many more, of those, probably Markaby is the closest to your idea, but the last commit on github is from 2008. Surely looking at _why's code should be entertaining.

Resources