On Fri, 1 Mar 2002, Stephan Michels wrote:
> On Fri, 1 Mar 2002, Christian Zoffoli wrote:
> > I have found a problem on the xupdate document submitted by
> > XMLDBTransformer to the XUpdateQueryService, it seems that the namespace
> > xmlns:xu="http://www.xmldb.org/xupdate" was erased by the original
> > document.
> >
> > Why ??
> >
> > ...after reading the bug pointed by Vadim Gritsenko at the beginning of
> > the code I substituted Xalan with other processors (saxon, xt) ...but
> > the result was the same. Any hints ?
> >
>
> > > I found that the problem with xupdate is due to xalan ...it
> > > erases a part of the submitted document (the namespace)
> > >
> > > <xu:modifications version="1.0"
> > > xmlns:xu="http://www.xmldb.org/xupdate\>
> > > <xu:update select="/users/user[@id = '1']/email">pippo</xu:update>
> > > </xu:modifications>
> > >
> > > became
> > >
> > > <?xml version="1.0" encoding="UTF-8"?>
> > >
> > > <xu:modifications version="1.0">
> > > <xu:update select="/users/user[@id =
> > > '1']/email">pippo</xu:update>
> > > </xu:modifications>
> > >
> > > and so it doesn't work.
>
> Thank you first.
>
> Why use the transformer not the org.apache.xml.serialize.XMLSerializer
> instead?
>
> Should I rewrite the transformer, or will be there a solution in the next
> time?
I have now simply replace the javax.xml.transform.sax.TransformerHandler
stuff by XMLSerializer to find the bug.
And now I got following exception:
Original exception : java.lang.ArrayIndexOutOfBoundsException: -1
at
org.apache.xerces.util.NamespaceSupport.popContext(NamespaceSupport.java:218)
at
org.apache.xml.serialize.XMLSerializer.endElementIO(XMLSerializer.java:400)
at
org.apache.xml.serialize.XMLSerializer.endElement(XMLSerializer.java:387)
at
org.apache.cocoon.transformation.XMLDBTransformer.endElement(XMLDBTransformer.java:480)
[..]
Perhaps it is the same error...
I attached a little test scenario and the patch.
Can anyone help me?
Thanx, Stephan Michels.
Index: XMLDBTransformer.java
===================================================================
RCS file:
/home/cvspublic/xml-cocoon2/src/scratchpad/src/org/apache/cocoon/transformation/XMLDBTransformer.java,v
retrieving revision 1.6
diff -u -r1.6 XMLDBTransformer.java
--- XMLDBTransformer.java 22 Feb 2002 06:58:03 -0000 1.6
+++ XMLDBTransformer.java 1 Mar 2002 14:18:07 -0000
@@ -72,12 +72,10 @@
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.modules.XUpdateQueryService;
-import javax.xml.transform.sax.TransformerHandler;
-import javax.xml.transform.sax.SAXTransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.TransformerConfigurationException;
+import org.apache.xml.serialize.Method;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
@@ -161,8 +159,7 @@
private static String XMLDB_QUERY_RESULT_ATTRIBUTE = "result";
/** The trax <code>TransformerFactory</code> used by this transformer. */
- private SAXTransformerFactory tfactory = null;
- private Properties format = new Properties();
+ private OutputFormat format;
/** The map of namespace prefixes. */
private Map prefixMap = new HashMap();
@@ -186,15 +183,13 @@
private String key;
private StringWriter queryWriter;
- private TransformerHandler queryHandler;
+ private XMLSerializer queryHandler;
/** True when inside <query> element. */
private boolean processing;
public void XMLDBTransformer() {
- format.put(OutputKeys.ENCODING, "utf-8");
- format.put(OutputKeys.INDENT, "no");
- format.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ format = new OutputFormat(Method.XML, "US-ASCII", false);
}
public void configure(Configuration configuration) throws ConfigurationException
{
@@ -236,18 +231,6 @@
}
/**
- * Helper for TransformerFactory.
- */
- protected SAXTransformerFactory getTransformerFactory()
- {
- if(tfactory == null) {
- tfactory = (SAXTransformerFactory) TransformerFactory.newInstance();
- tfactory.setErrorListener(new TraxErrorHandler(getLogger()));
- }
- return tfactory;
- }
-
- /**
* Generate the unique key.
* This key must be unique inside the space of this component.
*
@@ -342,13 +325,8 @@
if (!"delete".equals(operation)) {
// Prepare SAX query writer
queryWriter = new StringWriter(256);
- try {
- this.queryHandler =
getTransformerFactory().newTransformerHandler();
- this.queryHandler.setResult(new StreamResult(queryWriter));
-
this.queryHandler.getTransformer().setOutputProperties(format);
- } catch (TransformerConfigurationException e) {
- throw new SAXException("Failed to get transformer handler",
e);
- }
+
+ this.queryHandler = new XMLSerializer(queryWriter, format);
// Start query document
this.queryHandler.startDocument();
> cat example.xml
<?xml version="1.0"?>
<addresses version="1.0">
<address id="1">
<fullname>Andreas Laux</fullname>
<born day='1' month='12' year='1978'/>
<town>Leipzig</town>
<country>Germany</country>
</address>
</addresses>
> xindiceadmin ac -c /db -n addressbook
Created : /db/addressbook
> xindice ad -c /db/addressbook -f example.xml -n example
Added document /db/addressbook/example
> xindice xpath -c /db/addressbook -q /addresses/address[1]
<?xml version="1.0"?>
<address id="1" xmlns:src="http://xml.apache.org/xindice/Query"
src:col="/db/addressbook" src:key="example">
<fullname>Andreas Laux</fullname>
<born day="1" month="12" year="1978" />
<town>Leipzig</town>
<country>Germany</country>
</address>
> cat xupdate-example.xml
<?xml version="1.0"?>
<example>
<xindice:query type="update" oid="example"
xmlns:xindice="http://apache.org/cocoon/xmldb/1.0">
<xupdate:modifications version="1.0" xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:insert-after select="/addresses/address[1]" >
<xupdate:element name="address">
<xupdate:attribute name="id">2</xupdate:attribute>
<fullname>Lars Martin</fullname>
<born day='2' month='12' year='1974'/>
<town>Leizig</town>
<country>Germany</country>
</xupdate:element>
</xupdate:insert-after>
</xupdate:modifications>
</xindice:query>
</example>
> grep -A 7 "xupdate" sitemap.xmap
<map:match pattern="xupdate-example.xml">
<map:generate src="xupdate-example.xml"/>
<map:transform type="xmldb">
<map:parameter name="base" value="xmldb:xindice:///db/addressbook"/>
</map:transform>
<map:serialize type="xml"/>
</map:match>
> wget http://localhost:8080/cocoon/xupdate-example.xml
--20:34:00-- http://localhost:8080/cocoon/xupdate-example.xml
=> `xupdate-example.xml.1'
Verbindungsaufbau zu localhost:8080... verbunden!
HTTP Anforderung gesendet, auf Antwort wird gewartet... 200 OK
L�nge: nicht spezifiziert [text/xml]
0K @ 218.75 KB/s
20:34:00 (31.25 KB/s) - �xupdate-example.xml.1� gespeichert [224]
> cat xupdate-example.xml.1
<?xml version="1.0" encoding="UTF-8"?>
<example>
<xindice:query oid="example" type="update" result="failure"
xmlns:xindice="http://apache.org/cocoon/xmldb/1.0">Failed
to update resource example: 1</xindice:query>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]