[opencms-dev] Question about OpenCms Programming

Christof Dallermassl ce-christof.dallermassl at bearingpoint.com
Thu Nov 17 11:24:35 CET 2005


Hi!

> I've a question about the OpenCms Programming concerning creating and
> manipulating a XmlContentDocument. Meenwhile I can _create_ an empty
> XmlContentDocument:
> CmsObject.createResource(<path/filename>,<ContentID>) works fine ;-)
>
> But now I 've only the raw structure! How can I change the "values" with
> some Java-Functions? for example: How can I change from

// create a new content:
CmsObject cms; // get one or create one with username/password
CmsXmlContentDefinition contentDef = CmsXmlContentDefinition.unmarshal(cms, pathToXsdFile);
CmsXmlContent content = CmsXmlContentFactory.createDocument(cms, locale, "UTF-8", contentDef);

// or read an existing one:
CmsResource resource = cms.readResource(pathToResource);
CmsFile file = CmsFile.upgrade(resource, cms);

// change content:
content = CmsXmlContentFactory.unmarshal(cms, file);
content.getValue("name", locale).setStringValue(cms, "hans");

// write the content, or otherwise the changes are lost!:
file.setContents(content.marshal());
cms.writeFile(file);


regards
Christof



More information about the opencms-dev mailing list