There's no need to wrap the Saxon NodeInfo as a DOM Node just to discover an attribute value.
private String getNodeAttr(NodeInfo node, String attr) {
    return Navigator.getAttributeValue(node, "", attr)
If you're getting the same attribute repeatedly, then it would be even more efficient to convert the attribute name to an integer fingerprint once, and then use the fingerprint repeatedly via
Alternatively, why not get the attribute value in your XPath code rather than in your Java code?
Michael Kay

From: Shridhar Venkatraman []
Sent: 05 April 2009 08:34
Subject: [saxon] Speeding up getting attributes in Java


We are using Java to parse xml messages coming at us from a queue.

The XML is simple in structure;

<DESET  SOURCE="TRANSFORM" VERSION="01" TIMESTAMP="2008-10-16 10:12:52.0" ERROR="0">
    <DE NAME = "ACCTTYPE"      TYPE = "STRING" VALUE = "01"/>
    around 50 instances of 'DE'

We load it into a document this way;

      byte[] mybyte = txnstatsxml.trim().getBytes(); bais = new;
      InputSource is = new InputSource(bais);
      SAXSource ss = new SAXSource(is);
      doctxnstats = ((net.sf.saxon.xpath.XPathEvaluator) xpath).setSource(ss);

We then use compiled expressions to search for nodes like so;

n = (List) expr_DESET_DE.evaluate(doctxnstats, XPathConstants.NODESET);

When we find the nodes we look for attributes by calling this helper method like so;

private String getNodeAttr(NodeInfo node, String attr) {
    try {
         return NodeOverNodeInfo.wrap(node).getAttributes().getNamedItem(attr).getNodeValue();
        } catch (Exception e) { }
    return null;

The above method is eating 30% of the cpu used by our message consumer (70% includes MQ interfaces, some SQL inserts  and related commits) according to the profiler. It is invoked very often. Is there is a way to speed this attribute 'getting'? These messages come at us over 500 a sec.