[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Updating / replacing the content of a Container
On Wed, 25 Jul 2001 11:33:13 +0200
"Per Nyfelt" <per.nyfelt@nordicwave.com> wrote:
> Thanks for helping out Lars.
> Here's the usage:
>
> private void updateDOMDocument(String id) throws Exception {
> try {
> XMLResource resource = (XMLResource) col.getResource(id);
>
> Document document = (Document) resource.getContentAsDOM();
> Element root = document.getDocumentElement();
> // Change document by appending to an element data
>
> Text nameNode = document.createTextNode(" updateAddition");
> NodeList list = root.getElementsByTagName("testName");
> Node parent = list.item(0);
> parent.appendChild(nameNode);
>
> // insert a new element
> list = root.getElementsByTagName("levelZeroTests");
> Node levelZeroTests = list.item(0);
> Element testName = document.createElement("testName");
> levelZeroTests.appendChild(testName);
> Node name = document.createTextNode("testSAX");
> testName.appendChild(name);
>
> resource.setContentAsDOM(document); // here's where it fails
> col.storeResource(resource);
> }
> catch (Exception e) {
> e.printStackTrace();
> throw e;
> }
> }
>
> Here is the method that fails. I need to find a way to replace the content
> for the container with the new one. Deleting and recreating the container
> looks ugly i think, maybe there's a better way?
What about XUpdate? Ozone already supports the XUpdate specification.
Simple create an XUpdate string with your new content and perfom the
update method.
Lars
> public void setContentAsDOM( Node content ) throws XMLDBException {
> ExternalTransaction tx = database.newTransaction();
> try {
> if (content == null) {
> throw new XMLDBException(ErrorCodes.INVALID_RESOURCE);
> }
> if (content instanceof Document) {
> tx.begin();
> container.storeDOM((Document)content); // container is an
> XMLContainer
> tx.commit();
> }
> else {
> throw new XMLDBException(ErrorCodes.VENDOR_ERROR,"NOT
> IMPLEMENTED -
> Cannot store Nodes right now, must be a Document");
> }
> }
> catch (Exception e) {
> try {
> if (tx.getStatus() == tx.STATUS_ACTIVE)
> tx.rollback();
> throw new XMLDBException( ErrorCodes.VENDOR_ERROR,
> e.getMessage());
> }
> catch (Exception rollbackException) {
> throw new XMLDBException(ErrorCodes.VENDOR_ERROR,
> rollbackException.getMessage());
> }
> }
> }
>
> Hope this clarifies it.
>
> Best regards,
> Per
--
______________________________________________________________________
Lars Martin mailto:lars@smb-tec.com
SMB GmbH http://www.smb-tec.com
----------------------------------------------------------------------
Post a message: mailto:ozone-dev@ozone-db.org
Unsubscribe: mailto:ozone-dev-request@ozone-db.org?body=unsubscribe
Contact adminstrator: mailto:ozone-dev-owner@ozone-db.org
Read archived messages: http://www.ozone-db.org/
----------------------------------------------------------------------