Project

Profile

Help

Bug #4319

closed

Namespace declaration no longer serialized with Saxon 9.9.1-5

Added by Radu Coravu over 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2019-09-25
Due date:
% Done:

0%

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

Description

If a content handler outputs attributes in a certain namespace the Saxon transform will no longer add the necessary namespace declaration on the element. Sample code:

  public static void main(String[] args) throws TransformerFactoryConfigurationError, TransformerException, IOException {
	  Transformer transformer = TransformerFactory.newInstance().newTransformer();
	  XMLReader reader = new XMLReader() {
		private ContentHandler handler;
		@Override
		public void setProperty(String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException {
		}
		@Override
		public void setFeature(String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException {
		}
		@Override
		public void setErrorHandler(ErrorHandler handler) {
		}
		@Override
		public void setEntityResolver(EntityResolver resolver) {
		}
		@Override
		public void setDTDHandler(DTDHandler handler) {
		}
		
		@Override
		public void setContentHandler(ContentHandler handler) {
			this.handler = handler;
		}
		
		@Override
		public void parse(String systemId) throws IOException, SAXException {
			parse((InputSource)null);
		}
		
		@Override
		public void parse(InputSource input) throws IOException, SAXException {
			handler.startDocument();
			AttributesImpl attrs = new AttributesImpl();
			attrs.addAttribute("http://www.oxygenxml.com/schematron/validation", "elementURI", "oxy:elementURI", "CDATA", "abc");
			handler.startElement("", "elem", "elem", attrs);
			handler.endElement("", "elem", "elem");
			handler.endDocument();
		}
		@Override
		public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
			return null;
		}
		@Override
		public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
			return false;
		}
		@Override
		public ErrorHandler getErrorHandler() {
			return null;
		}
		@Override
		public EntityResolver getEntityResolver() {
			return null;
		}
		public DTDHandler getDTDHandler() {
			return null;
		}
		@Override
		public ContentHandler getContentHandler() {
			return handler;
		}
	};
	  SAXSource src = new SAXSource(reader, new InputSource("file://abc.txt"));
	  StringWriter sw = new StringWriter();
	  StreamResult res = new StreamResult(sw);
	  transformer.transform(src, res);
	  sw.close();
	  System.err.println(sw.toString());
  }

With Saxon 9.8 the code returns:

<?xml version="1.0" encoding="UTF-8"?><elem xmlns:oxy="http://www.oxygenxml.com/schematron/validation" oxy:elementURI="abc"/>

but with Saxon 9.9.1-5 it returns:

<?xml version="1.0" encoding="UTF-8"?><elem oxy:elementURI="abc"/>

Please register to edit this issue

Also available in: Atom PDF