craigmiller160
craigmiller160

Reputation: 6273

Saxon s9api: When to expect TinyDocumentImpl vs DocumentImpl

My company makes heavy use of XSLT in our product, and we're about to migrate away from Java's javax.xml API and to Saxon's s9api. Because of this, I've been tasked with exploring the new API and figuring out what changes we need to make.

One of the big things that is bugging me is the Saxon NodeInfo. Specifically, for whole XML documents, there are two implementations: TinyDocumentImpl, and DocumentImpl. They do not share a common API, and I have yet to find good documentation on when to use either one.

So my question is: when should I expect one versus the other? What kind of rules determine which one is returned by a given Saxon operation?

An extra point: so far in my experimentation, I see TinyDocumentImpl whenever I use the Saxon DocumentBuilder to load in a document, but I have seen DocumentImpl as the NodeInfo underlying the XdmNode parameter of a MessageListener2 implementation, which receives the output of an xsl:message.

Upvotes: 1

Views: 166

Answers (1)

Michael Kay
Michael Kay

Reputation: 163468

Saxon's NodeInfo interface should contain all the methods that are normally needed to manipulate nodes. In fact, for most s9api applications, you shouldn't need to drop down below the higher-level XdmNode interface. There are many different concrete implementations of the NodeInfo interface, including DocumentImpl and TinyDocumentImpl which you mention, but unless you have very strong reasons you shouldn't be concerned with the concrete implementation, since it's something that might change depending on configuration settings or even on the version of Saxon that you are using.

You haven't said what you actually want to do with these nodes, but I think it can probably be achieved using methods available on NodeInfo or XdmNode.

A little bit of extra information: TinyDocumentImpl represents a document node in the "tiny tree" which is Saxon's default tree model. DocumentImpl is a document node in the "linked tree" which is used in cases where it gives benefits. The xsl:message instruction generates (according to the spec) an XML document, but in the vast majority of cases, the XML document contains only a document node and a single text node. When that is the case, building a LinkedTree performs better than building a TinyTree, so we choose that option. But as I said before, you really don't want to know that...

Upvotes: 1

Related Questions