You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Erik Norvelle <er...@norvelle.net> on 2000/03/24 11:31:54 UTC

Attribute mangling with xspCurrentNode.appendChild( Node )

I am experiencing problems with xspCurrentNode.appendChild( Node newNode )
under Cocoon 1.7.  I use this utility function to append a DOM tree
generated by some custom Java classes.

The problem is that using appendChild results in XML output with the
attribute values shifted to sibling nodes, or not appearing at all.

So, for instance, given a DOM tree representing the following:

<chapter>
   <quote number="1">I cannot believe it is not butter... </quote>
   <quote number="2">Another quote... </quote>
</chapter>

the resulting XML from Cocoon is:

<chapter>
   <quote>I cannot believe it is not butter... </quote>
   <quote number="1">Another quote... </quote>
</chapter>

The above result comes from an XSP which has an XSL transform applied, to
remove the <page> tag from the output.  If I disable the XSLT, I get:

<page>
<chapter>
   <quote>I cannot believe it is not butter... </quote>
   <quote>Another quote... </quote>
</chapter>
</page>

Note that *no* attributes come up at all.  So, the attributes have to be
there (because Xalan can see them), but they are getting moved to the wrong
nodes or are getting deleted entirely.

So far as I can tell, my custom classes are generating the DOM tree
appropriately (I have run an extensive debug session on them, and the
child/parent relations for the element & attribute nodes all come up
correctly).  Therefore, the logical assumption is that the error occurs in
the appendChild() method.  Following the is source for the XSP that
generates the problems:

<?xml version="1.0"?>

<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>
<?xml-stylesheet href="get.xsl" type="text/xsl"?>

<!-- Written by Erik Norvelle - "erik@norvelle.net" -->

<xsp:page
  language="java"
  xmlns:xsp="http://www.apache.org/1999/XSP/Core">

	<xsp:structure>
		<xsp:include>java.sql.*</xsp:include>
		<xsp:include>dll.adaptive.AdaptiveDBConnection</xsp:include>
		<xsp:include>dll.sqldom.XMLRetrieval</xsp:include>
		<xsp:include>dll.util.*</xsp:include>
	</xsp:structure>

 <page>
 <xsp:logic>
	// Get the parameters (i.e. document name and XML content)
	String documentName = request.getParameter("document");
	String result = "OK";
	Debug debug = new Debug( servletContext );

	// Implement a storage object and use it to retrieve a DOM Document to
insert
	try {
		Connection conn = AdaptiveDBConnection.getConnection();
		XMLRetrieval storage = new XMLRetrieval( conn, debug );
		AdaptiveDBConnection.release( conn );
		Node newNode = storage.getDocumentRoot( documentName, document );
		int count = NodeCounter.count( newNode );
		debug.log( "Successfully created a DOM with " + count + " nodes" );
		xspCurrentNode.appendChild( newNode );
	}
	catch (Exception ex) { result = ex.toString(); }
	servletContext.log( "GET request for document " + documentName + ", status:
" + result );
 </xsp:logic>
 </page>
</xsp:page>

Has anyone got any idea what might be causing the appendChild() routine to
malfunction?

-Erik

--------------------------------------------+
Erik Norvelle                               |
Support Systems Analyst, Sr.                |
The University of Arizona                   |
College of Agriculture                      |
Educational Communications and Technologies |
email:  norvelle@ag.arizona.edu             |
phone:  520-621-7663                        |
fax:    520-621-9889                        |
--------------------------------------------+
Credo in unum Deum                          |
--------------------------------------------+