[opencms-dev] how to update xml values within a CmsFile

Steve Bryan steve at bright-interactive.com
Thu May 29 14:15:36 CEST 2008


Hi Frank

There may be a better way, in which case I would like to hear - but
otherwise you can extract the dom4j Document, and work with that directly -
you would need to look at the API doc for Dom4j if you are not familiar with
it.

eg
CmsXmlContent content = CmsXmlContentFactory.unmarshal(cmsObject, file);
String sContent = content.toString();
Document doc = CmsXmlUtils.unmarshalHelper(sContent, null);

// Work with doc...

String sNewContent = CmsXmlUtils.marshal(doc, CmsEncoder.ENCODING_UTF_8);

					
// Save the contents
file.setContents(sNewContent.getBytes());
cmsObject.writeFile(file);


-----Original Message-----

Date: Wed, 28 May 2008 18:21:33 -0600
From: frankg <fg_salesforce at hotmail.com>
Subject: [opencms-dev] how to update xml values within a CmsFile
To: <opencms-dev at opencms.org>
Message-ID: <BLU119-W103B04F77D525B62EFE6A884BF0 at phx.gbl>
Content-Type: text/plain; charset="windows-1252"

Hi,
 
Given certain conditions, I'm trying to update an xml value within a CmsFile
programmatically.  I've gotten to a point where I've been able to unmarshal
the file and can retrieve the value, but am looking for some direction on
how to update this value.  Any help would be appreciated.
 
This is what I have so far:
 
CmsFile resourceFile = CmsFile.upgrade(cr, cms);CmsXmlContent xmlDocument =
CmsXmlContentFactory.unmarshal(cms, resourceFile, true);Locale locale = new
Locale(cms.getRequestContext().getLocale().toString());String value =
xmlDocument.getStringValue(cms, "Section/ABC", locale);
 
// if value is true, then update the value
if ("true".equals(value)) {
     // ???
 
}
 
Thanks so much in advance!
 
Frank




More information about the opencms-dev mailing list