Migrate from GitHub to SourceForge with this tool. Check out all of SourceForge's recent improvements.

#6 Highlighted output: first test


[[ the mailing list doesn't support attachment, I open a new feature request to upload the file ]]

--- copy of the email sent to the list ---


I did some tests with highlighting Saxon's output in a
JTextPane. You can see in attachment a complete application
that does the job from a transform done by Saxon.

Just copy the files in a package "styled" in any project
in NB (I have a special project "Drafts" for this purpose).
The project must be linked to the libraries "Saxon8902B" and
"CommonsLang". The commons-lang JAR from Apache can be
found there:


Then just run the class ColouredJAXPResult (S-F6 or

And voila!

There is a little bug: when the total length of the
attributes of an element is too long, Saxon outputs them on
several lines. This is no longer the case here. I don't
know if I'm doing something wrong or if it is Saxon (but the
simple example I've just sent to the Saxon ML suggests this
would be Saxon...)

There are a few comments in the source files. Please do
ask me if your have any question.

What do you think? Do you agree on the principle? If you
do, I will begin to think about the way to integrate it into
Kernow. IMHO the harder part will be to tell the
SerializerFactory when to output to the text pane, and when
to just let Saxon output to a file or whatever. I have some
ideas, but I need to check the lifecycle of the objects




  • Florent Georges

    Florent Georges - 2007-08-16
  • Florent Georges

    Florent Georges - 2007-08-17

    Logged In: YES
    Originator: YES

    I attach a little sequence diagram to help understand this piece of code (kernow-xmlemitter-highlighter.jpg).

    It represents a single call to startElement() on an Emitter by Saxon. XMLEmitter and MyXMLEmitter are actually the same object, I just separared them to make the distinction clearer. First the standard implementation (of XMLEmitter) is called. As MyXMLEmitter has set its own StringWriter as the writer of the object, the output is accumulated there.

    It then get this little chunk of output and clear the StringWriter. It parses this chunk of data. That's not too complex, as the format is quite well-known: "<prefix(:local)?".

    For each of the lexical part of the string (here "<", "prefix" and maybe ":" and "local") it send the right event to its LexicalDestination.

    Then Saxon will call for instance attribute() and the same kind of sequence will happen (but with a single one attribute instead of the start of an element tag).

    File Added: kernow-xmlemitter-highlighter.jpg


Log in to post a comment.