Project

Profile

Help

Bug #4300

closed

Getting warnings using XPathExecutable

Added by Rick Vlaming over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
s9api API
Sprint/Milestone:
-
Start date:
2019-08-26
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.9, trunk
Fix Committed on Branch:
9.9, trunk
Fixed in Maintenance Release:
Platforms:

Description

We are doing a saxon:deep-equal via the following statements:

		XPathExecutable xx = xpath.compile("saxon:deep-equal($vmgv:node1, $vmgv:node2, () ,'w?')");


		XPathSelector selector = xx.load();
		selector.setVariable(new QName("urn:us:xpath:var", "node1"), node1);
		selector.setVariable(new QName("urn:us:xpath:var", "node2"), node2);

		XdmAtomicValue deepEqualResult = (XdmAtomicValue) selector.evaluateSingle();

In a unittest warnings are showed in the console when there are differences. How can I get these warnings in my application-code? An errorlistener can be set on a XSLT compiler but not on the XPathCompiler.

Actions #1

Updated by Michael Kay over 2 years ago

Try selector.getUnderlyingXPathContext().setErrorListener()

Actions #2

Updated by Rick Vlaming over 2 years ago

Tried but unfortunately not working.

When putting breakpoints on constructor and all methods in the LocalErrorListener-class the only stop is in the constructor.


	private boolean isDeepEqual(XdmNode node1, XdmNode node2) throws SaxonApiException {
		XPathCompiler xpath = processor.newXPathCompiler();
		ItemTypeFactory itf = new ItemTypeFactory(processor);
		ItemType decimalType = itf.getAtomicType(new QName("http://www.w3.org/2001/XMLSchema", "decimal"));
		xpath.declareVariable(new QName("urn:us:xpath:var", "node1"));
		xpath.declareVariable(new QName("urn:us:xpath:var", "node2"));
		xpath.declareNamespace("vmgv", "urn:us:xpath:var");
		xpath.declareNamespace("saxon", "http://saxon.sf.net/");
		XPathExecutable xx = xpath.compile("saxon:deep-equal($vmgv:node1, $vmgv:node2, () ,'w?')");

		XPathSelector selector = xx.load();
		selector.getUnderlyingXPathContext().setErrorListener(new LocalErrorListener());
		selector.setVariable(new QName("urn:us:xpath:var", "node1"), node1);
		selector.setVariable(new QName("urn:us:xpath:var", "node2"), node2);

		XdmAtomicValue deepEqualResult = (XdmAtomicValue) selector.evaluateSingle();
		return deepEqualResult.getBooleanValue();
	}

	private class LocalErrorListener implements UnfailingErrorListener {
		private final StringBuilder errors;

		LocalErrorListener() {
			errors = new StringBuilder();
		}

		@Override
		public void warning(TransformerException e) {
			errors.append(e.getMessage());
		}

		@Override
		public void error(TransformerException e) {
			errors.append(e.getMessage());
		}

		@Override
		public void fatalError(TransformerException e) {
			errors.append(e.getMessage());
		}

		public String getErrors() {
			return errors.toString();
		}
	}

Actions #3

Updated by Michael Kay over 2 years ago

  • Description updated (diff)
  • Category set to s9api API
  • Assignee set to Michael Kay
Actions #4

Updated by Michael Kay over 2 years ago

It turns out the warnings are always going to the ErrorListener associated with the Configuration. So it will have to be processor.getUnderlyingConfiguration().setErrorListener(....)

Unfortunately this sets the ErrorListener globally which isn't ideal.

I have patched DeepEqual() to use the ErrorListener from the XPathContext rather than from the Configuration. Unfortunately this changes the interface to DeepEqual.deepEquals() which is a public method that some users might be using.

Actions #5

Updated by Michael Kay over 2 years ago

  • Status changed from New to Resolved
  • Priority changed from Low to Normal
  • Applies to branch 9.9, trunk added
  • Fix Committed on Branch 9.9, trunk added

For 10.0 I have gone further. 10.0 has a new ErrorReporter interface superseding ErrorListener and I have added the ability to add an ErrorReporter to both XPathCompiler and XPathSelector to catch static and dynamic warnings respectively.

Actions #6

Updated by Michael Kay over 2 years ago

  • Tracker changed from Support to Bug
Actions #7

Updated by Rick Vlaming over 2 years ago

Thank you Michael. I will look into the processor.getUnderlyingConfiguration().setErrorListener(....) . And nice you gone further for 10.0. What will be de release date for that?

Actions #8

Updated by O'Neil Delpratt over 2 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in Maintenance Release 9.9.1.5 added

Bug fix applied in the Saxon 9.9.1.5 maintenance release.

Please register to edit this issue

Also available in: Atom PDF