views:

412

answers:

1

I'm using the built-in Java XML Transformer to serialize an XML document into text. I'm having a problem however when I am outputting in HTML mode.

Whenever I insert a head element the built-in transformer decides to insert a META tag with content-type data. I don't want this tag inside my data and I can't seem to find an output parameter that will disable this feature. I know I could build an xslt stylesheet and strip the tag in question, but it would be simpler just to be able to set a parameter on the transformer itself that disables it.

You might respond with "but you really should have this tag" -- trust me, I don't need it, for brevities sake I won't go into it.

Sample code

Document d; 
//d = <html><head><title></title></head><body></body></html>

Transformer t; //properly inited with no xslt specified

t.setOutputProperty(OutputKeys.METHOD,"html");
t.setOutputProperty(OutputKeys.INDENT,"no");
t.transform(new DOMSource(d), result);

System.out.println(result);

returns

<html><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><title></title><style type="text/css"></style></head><body></body></html>

Case in point, I don't want that META tag there. How do i get rid of it in the easiest way possible?

UPDATE:

I've run across the option {http://xml.apache.org/xalan}omit-meta-tag which is supposed to do what I'm looking for. However it seems as though it's being ignored.

A: 

This is a complicated situation, as it seems the "{http://xml.apache.org/xalan}omit-meta-tag" is ignored in the built-in java transform.

So the short answer is to download something like xalanj and put it in your classpath manually.

Mike
If you do that, you'll have to ensure that you put it in the endorsed directory, so that it overrides the version built in to Java. See http://java.sun.com/javase/6/docs/technotes/guides/standards/ for details.
Dominic Mitchell