You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Simon Collins <sc...@fastmail.fm> on 2004/04/14 14:44:28 UTC
DOMStreamer namespace problems
Hi all,
I was having a problem with Cocoon Forms down where I was losing the
namespace prefix mapping declaration on the root element when I saved the
form contents to a DOM document and then serialized that out to an XML
file.
I've found a workaround for now but there seems to be a bug somewhere. It
doesn't appear to be a forms related issue but rather one with
org.apache.cocoon.xml.DOMStreamer which is used like this in my code (and
in the Form GUI Cocoon sample):
-- snip --
var source = null;
var resolver = null;
var outputStream = null;
try {
resolver =
cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
source = resolver.resolveURI(uri);
var tf =
Packages.javax.xml.transform.TransformerFactory.newInstance();
if (source instanceof
Packages.org.apache.excalibur.source.ModifiableSource
&&
tf.getFeature(Packages.javax.xml.transform.sax.SAXTransformerFactory.FEATURE))
{
outputStream = source.getOutputStream();
var transformerHandler = tf.newTransformerHandler();
var transformer = transformerHandler.getTransformer();
transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.INDENT,
"true");
transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.METHOD,
"xml");
transformerHandler.setResult(new
Packages.javax.xml.transform.stream.StreamResult(outputStream));
var streamer = new
Packages.org.apache.cocoon.xml.dom.DOMStreamer(transformerHandler);
streamer.stream(document);
-- snip --
By default, DOMStreamer uses the NamespaceNormalizingDOMStreamer inner
class to write out SAX events. If I turn this off with
streamer.setNormalizeNamespaces(false);
then it uses DefaultDOMStreamer and the document is correctly written out
with the namespace declaration added.
>From a bit of debugging it seems like NamespaceNormalizingDOMStreamer is
spitting out the correct SAX events but for some reason they're not
making it into to the output XML.
If you want to try and replicate the problem just use the Cocoon Forms
GUI Builder sample and submit the form. Then look at
forms/form_model_gui_data-result.xml. The namespace declaration for
prefix "fd" should be missing on the root element.
I'm using Apache Tomcat/4.1.27, JDK 1.4.2_04-b05 with the nightly build
of 2.1.5 for 6/4/04.
Anyone got any ideas as to why this might be happening?
cheers,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: DOMStreamer namespace problems
Posted by Simon Collins <sc...@fastmail.fm>.
Thanks Bruno,
On Wed, 14 Apr 2004 19:36:12 +0200, "Bruno Dumon"
<br...@outerthought.org> said:
> > I was having a problem with Cocoon Forms down where I was losing the
> > namespace prefix mapping declaration on the root element when I saved the
> > form contents to a DOM document and then serialized that out to an XML
> > file.
>
> Note that JXPath (the XPath engine used by the binding framework)
> doesn't support namespaces. I don't how it handles documents that
> actually have namespaces.
>
I wondered about that. Strange that it seems to work with namespaces
though even when adding new nodes in but I'm not complaining if it works
:)
> >
> > >From a bit of debugging it seems like NamespaceNormalizingDOMStreamer is
> > spitting out the correct SAX events but for some reason they're not
> > making it into to the output XML.
>
> If you could somehow put the LogTransformer in there that would be very
> helpful. Especially to compare the output of the two DOMStreamers.
Yep, I'll give that a go and see if I can turn anything else up.
Cheers,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: DOMStreamer namespace problems
Posted by Bruno Dumon <br...@outerthought.org>.
On Wed, 2004-04-14 at 14:44, Simon Collins wrote:
> Hi all,
>
> I was having a problem with Cocoon Forms down where I was losing the
> namespace prefix mapping declaration on the root element when I saved the
> form contents to a DOM document and then serialized that out to an XML
> file.
Note that JXPath (the XPath engine used by the binding framework)
doesn't support namespaces. I don't how it handles documents that
actually have namespaces.
>
> I've found a workaround for now but there seems to be a bug somewhere. It
> doesn't appear to be a forms related issue but rather one with
> org.apache.cocoon.xml.DOMStreamer which is used like this in my code (and
> in the Form GUI Cocoon sample):
>
> -- snip --
>
> var source = null;
> var resolver = null;
> var outputStream = null;
> try {
> resolver =
> cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
> source = resolver.resolveURI(uri);
> var tf =
> Packages.javax.xml.transform.TransformerFactory.newInstance();
>
> if (source instanceof
> Packages.org.apache.excalibur.source.ModifiableSource
> &&
> tf.getFeature(Packages.javax.xml.transform.sax.SAXTransformerFactory.FEATURE))
> {
>
> outputStream = source.getOutputStream();
> var transformerHandler = tf.newTransformerHandler();
> var transformer = transformerHandler.getTransformer();
> transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.INDENT,
> "true");
> transformer.setOutputProperty(Packages.javax.xml.transform.OutputKeys.METHOD,
> "xml");
> transformerHandler.setResult(new
> Packages.javax.xml.transform.stream.StreamResult(outputStream));
>
> var streamer = new
> Packages.org.apache.cocoon.xml.dom.DOMStreamer(transformerHandler);
>
> streamer.stream(document);
>
> -- snip --
>
> By default, DOMStreamer uses the NamespaceNormalizingDOMStreamer inner
> class to write out SAX events. If I turn this off with
>
> streamer.setNormalizeNamespaces(false);
>
> then it uses DefaultDOMStreamer and the document is correctly written out
> with the namespace declaration added.
>
> >From a bit of debugging it seems like NamespaceNormalizingDOMStreamer is
> spitting out the correct SAX events but for some reason they're not
> making it into to the output XML.
If you could somehow put the LogTransformer in there that would be very
helpful. Especially to compare the output of the two DOMStreamers.
--
Bruno Dumon http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org bruno@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org