It looks like your XMLStreamReader is returning null in response to the call getAttributeType(). That's not a documented behaviour of this method - unfortunately the StAX specification is rather weak on this kind of thing, and each new implementation that's tested tends to throw up problems like this. I'll put out a patch for it.
 
Meanwhile I've discovered that StAXSource and StAXResult are in fact part of the JAXP 1.4 distribution (not JSR 173 as advertised), and there's no difficulty adding support to Saxon except possibly the configuration issues that arise from another external dependency. I'll add this to the next release (9.2). Meanwhile you could actually configure this support yourself if you want to:
 
configuration.setSourceResolver(
  new SourceResolver() {
   public Source resolveSource(Source source, Configuration config) throws XPathException {
      if (source instanceof StAXSource) {
        XMLStreamReader reader = ((StAXSource)source).getXMLStreamReader();       

        StaxBridge bridge = new StaxBridge();

        bridge.setXMLStreamReader(omElement.getXMLStreamReader());

        PullSource ps= new PullSource(bridge);

        return ps;

     } else {

       return source;

    }

  }

 

Michael Kay

http://www.saxonica.com/



From: Luis Costa [mailto:luis.costa@alert.pt]
Sent: 04 February 2009 12:40
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: Re: [saxon] StAXSource as sorce to performtransformationusingsaxonb9-1-0-5j problem

Hi Michael,

I try your suggestion A) but I received error B)

Am I doing something wrong?

Many Thanks,

Luis Costa.

 

A)

ByteArrayOutputStream bos = new ByteArrayOutputStream();

Result result = new StreamResult(bos);

StaxBridge bridge = new StaxBridge();

bridge.setXMLStreamReader(omElement.getXMLStreamReader());

PullSource source = new PullSource(bridge);

transformer.transform(source, result)

 

 

B)

java.lang.NullPointerException

      at net.sf.saxon.pull.StaxBridge$StaxAttributes.isIdref(StaxBridge.java:779)

      at net.sf.saxon.pull.StaxBridge$StaxAttributes.getProperties(StaxBridge.java:653)

      at net.sf.saxon.pull.PullPushTee.copyEvent(PullPushTee.java:88)

      at net.sf.saxon.pull.PullPushTee.next(PullPushTee.java:60)

      at net.sf.saxon.pull.PullConsumer.consume(PullConsumer.java:32)

      at net.sf.saxon.pull.PullPushCopier.copy(PullPushCopier.java:35)

      at net.sf.saxon.event.Sender.sendPullSource(Sender.java:470)

      at net.sf.saxon.event.Sender.send(Sender.java:181)

      at net.sf.saxon.event.Sender.send(Sender.java:50)

      at net.sf.saxon.Controller.transform(Controller.java:1611)

 

From: Michael Kay [mailto:mike@saxonica.com]
Sent: quarta-feira, 4 de Fevereiro de 2009 12:12
To: 'Mailing list for the SAXON XSLT and XQuery processor'
Subject: Re: [saxon] StAXSource as sorce to perform transformationusingsaxonb9-1-0-5j problem

 

The classes StAXOMBuilder and OMElement appear to be part of the Apache AXIOM product. There is no integration between Saxon and Axiom.

 

However, the only problem this causes is that I can't run your code: it's easy to change your example so it doesn't use these classes, but just binds an XMLStreamReader to the source XML file directly.

 

This then leads to the question of whether Saxon should recognize the net.sf.saxon.transform.StAXSource class.  To be honest, I have no idea where this class came from. It's in JDK 1.6, and it claims in the Javadoc that it's part of JSR 173, but if you go to the JSR 173 specification, or to the free-standing JAR files distributed with JSR 173, then it's not there. I can't find any version of this class that's available for use with JDK 1.4 or JDK 1.5, and if that's the case then it means that it can't be used with Saxon.

 

Incidentally, the claim in the Javadoc that "StAXSource can be used in all cases that accept a Source, e.g. Transformer, Validator which accept Source as input. " is absurd. A new implementation of Source, unless it subclasses an existing supported implementation such as SAXSource, will only work with software that has been modified to recognize it.

 

I will raise these questions with the JAXP expert group and see if they can shed any light.

 

Meanwhile, if you want to use an XMLStreamReader to provide input to a transformation, you can use a net.sf.saxon.pull.PullSource, which wraps an instance of net.sf.saxon.pull.StaxBridge:

 

StaxBridge bridge = new StaxBridge();

bridge.setXMLStreamReader(reader);

PullSource source = new PullSource(bridge);

transformer.transform(source, result)

 

Michael Kay

http://www.saxonica.com/

 


From: Luis Costa [mailto:luis.costa@alert.pt]
Sent: 04 February 2009 10:17
To: saxon-help@lists.sourceforge.net
Subject: [saxon] StAXSource as sorce to perform transformation usingsaxonb9-1-0-5j problem

Hi all,

I’m trying to validate a xml to a schematron,

1.       I transform my shematron code to a stylesheet;

2.       I submit the xml to the stylesheet as you can see below A)

3.       I’m using the latest version of saxon(saxonb9-1-0-5j) and I’m getting the following error B) (net.sf.saxon.trans.XPathException: A source of type javax.xml.transform.stax.StAXSource is not supported in this environment)

 

Questions:

1.       Is this a known error?

2.       What is your advice?

 

Many thanks,

Luis Costa

 

 

A)

String strStylSheetPath = "C:/dummy.xsl";

String omElemPath = "C:/ dummy.xml";

InputStream imp = new FileInputStream(new File(omElemPath));

InputStreamReader impsr = new InputStreamReader(imp);

Reader reader = impsr;

XMLStreamReader parser = null;

try {

                parser = XMLInputFactory.newInstance().createXMLStreamReader(reader);

} catch (XMLStreamException e) {

               

e.printStackTrace();

} catch (FactoryConfigurationError e) {

                e.printStackTrace();

}

StAXOMBuilder builder = new StAXOMBuilder(parser);

OMElement omMetadata =  builder.getDocumentElement();

FileInputStream fileInputStream = new FileInputStream(strStylSheetPath);

Source srcStylSheet = new StreamSource(fileInputStream);

System.setProperty("javax.xml.transform.TransformerFactory", TransformerFactoryImpl.class.getName());

Transformer xDSFieldsValidationStylesheet = TransformerFactoryImpl.newInstance().newTransformer(srcStylSheet);

Source src = new StAXSource(omMetadata.getXMLStreamReader());

ByteArrayOutputStream bos = new ByteArrayOutputStream();

Result rs = new StreamResult(bos);

try

{

// this fails …

xDSFieldsValidationStylesheet.transform(src, rs);

}

catch(Exception e)

{

                System.out.println(e);

}

 

 

 

B)

net.sf.saxon.trans.XPathException: A source of type javax.xml.transform.stax.StAXSource is not supported in this environment

 

 

 

 

Thank you for your attention and best regards,

 

Luís Costa

Software Developer

 

luis.costa@alert.pt

 

www.alert-online.pt

 

 

ALERT Life Sciences Computing, S.A.

Edifício Lake Towers – pisos 7, 8 e 9

Rua Daciano Baptista Marques, n.º 245

4400-617 Vila Nova de Gaia

Portugal

Tel.: +351 22 832 89 80

Fax.: +351 22 832 89 82

info@alert.pt

 

This e-mail is privileged, confidential and contains private information. Any reading, retention, distribution or copying of this communication by any person other than its intended recipient is prohibited.