Hi,
I found a bug in InsertAtttribute.java when inserting attributes with
namespaces:
} else {
attribute =
contextNode.getOwnerDocument().createAttributeNS( namespaceURI, qName );
attribute.setValue( data );
contextNode = ((Element)contextNode).setAttributeNodeNS(
attribute );
if (qName.indexOf( ":" )>=0) {
contextNode.getOwnerDocument().getDocumentElement().setAttribute(
"xmlns:" +
qName.substring( 0, qName.indexOf( ":" ) ),
namespaceURI );
}
}
contextNode is set to "null" when inserting a attributes that does not
yet exist, after that contextnode is used so you get a nullpointer
exception.
setAttributeNodeNS returns an Attr if it replaces a existing Attr
otherwise "null" so it seems to me that the "contextNode =" is wrong
(also in the non-namespace part but there it doesn't cause a nullpointer
exception).
greetings,
jeroen
USE-CASE:
-----------------
Notice in this use case: I still think the namespace declaration
shoudn't move to the document element.
input:
<?xml version="1.0"?>
<addresses>
<address name="Andreas">
<town>New York</town>
</address>
<address name="Lars">
<town>Los Angeles</town>
</address>
</addresses>
updates:
<lexus:modifications version="1.0"
xmlns:lexus="http://www.xmldb.org/xupdate">
<lexus:insert-after select="/addresses/address[position()=2]">
<address:address xmlns:address="http://www.x-hive.com/address"
address:name="Jeroen">
<address:town>Rotterdam</address:town>
</address:address>
</lexus:insert-after>
</lexus:modifications>
result:
<?xml version="1.0"?>
<addresses>
<address name="Andreas">
<town>New York</town>
</address>
<address name="Lars">
<town>Los Angeles</town>
</address>
<address:address xmlns:address="http://www.x-hive.com/address"
address:name="Jeroen">
<address:town>Rotterdam</address:town>
</address:address>
</addresses>
--
X-Hive Corporation
e-mail: [EMAIL PROTECTED]
phone: +31 10 7108622
http://www.x-hive.com
----------------------------------------------------------------------
Post a message: mailto:[EMAIL PROTECTED]
Unsubscribe: mailto:[EMAIL PROTECTED]
Contact administrator: mailto:[EMAIL PROTECTED]
Read archived messages: http://archive.xmldb.org/
----------------------------------------------------------------------