[opencms-dev] Problem for update one field xmlcontent programmatic

Brabenetz, Harald harald.brabenetz at bearingpointconsulting.com
Thu Jun 24 16:45:58 CEST 2010


With "xmlcontent = CmsXmlContentFactory.createDocument(...)" a new document will be created.
try "xmlcontent = CmsXmlContentFactory.unmarshal(CmsObject, CmsFile)" instead.

Or use the Beta-1 Version of the Commons Module:
http://bp-cms-commons.sourceforge.net/m2site/infonova/modules/at.infonova.opencms.modules.commons/1.0-B1/

There is a XmlContentEditorHelper:
-------------------------------
 XmlContentEditorHelper helper = new XmlContentEditorHelper(getCmsObject(), CmsFile, Locale);

 // edit XML Content
 helper.setValue("Title", "Some test Message");

 // save XML-Content.
 helper.writeContent();
-------------------------------

with friendly regards,
Harald


________________________________

From: opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Deiverson Silveira
Sent: Donnerstag, 24. Juni 2010 16:14
To: opencms-dev at opencms.org
Subject: [opencms-dev] Problem for update one field xmlcontent programmatic


Hi List,

I have problem then update information 1 field in my xmlcontent, I lost all information and I dont cant update 1 field only, and preserve all other.

Anyone know how to do this? Update only one field XmlContent without losing too much?


Thank you,


Deiverson Silveira




The code:

String sName = "test field update";

try{

CmsXmlContentDefinition cd =  CmsXmlContentDefinition.unmarshal(cmsObject, "/system/modules/my.project/schemas/city.xsd");
CmsXmlContent xmlcontent = CmsXmlContentFactory.createDocument(cmsObject,locale,org.opencms.main.OpenCms.getSystemInfo().getDefaultEncoding(),cd);

xmlcontent.getValue("Title", Locale.ENGLISH).setStringValue(cmsObject, String.valueOf(sName));

// Dont work.......... lost information field past =/
xmlcontent.getValue("SubTitle", Locale.ENGLISH).setStringValue(cmsObject, String.valueOf(xmlcontent.getStringValue(cmsObject,"SubTitle", Locale.ENGLISH)));
//  I need redefinition all fields again???

byte[] content = xmlcontent.marshal();

String nameFile = "/test.html";

//   cmsObject.writeFile(nameFile , org.opencms.main.OpenCms.getResourceManager().getResourceType("cidade").getTypeId(),content,new ArrayList());
//   cmsObject.createResource("nameFile", org.opencms.main.OpenCms.getResourceManager().getResourceType("contato").getTypeId(),content,new ArrayList());

   cmsObject.lockResource(nameFile);
   cmsObject.replaceResource(nameFile, org.opencms.main.OpenCms.getResourceManager().getResourceType("cidade").getTypeId(),content,new ArrayList());

   cmsObject.unlockResource(nameFile);
//   cmsObject.publishResource(nameFile);

 }
catch(Exception exc)
{
out.println("Erro: " + exc.getMessage());

}

INFONOVA GmbH
Sitz: Unterpremst?tten bei Graz
Firmenbuchgericht: Landesgericht f?r ZRS Graz
Firmenbuchnummer: FN 44354b



More information about the opencms-dev mailing list