I am putting HTML into the component field using the core service. I write the following code:
ComponentData componentData=(ComponentData)client.getDefaultDataItemType.COMPONENT,folderId, new ReadOptions());
componentData.setId("tcm:0-0-0");
componentData.setTitle("componentName");
componentData.setComponentType(ComponentType.NORMAL);
LinkToSchemaData lstd=new LinkToSchemaData();
//lstd.setIdRef("tcm:22-21411-8");
lstd.setIdRef(schemaTCM);
componentData.setSchema(lstd);
componentData.setContent("<Content xmlns='"+schemaUID+"'><Body><div xmlns='http://www.w3.org/1999/xhtml'>"+html+"</div></Body></Content>");
componentData=(ComponentData)client.create(componentData, new ReadOptions());
It has given me the following error many times.
javax.xml.ws.soap.SOAPFaultException: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://www.sdltridion.com/ContentManager/CoreService/2012:data. The InnerException message was 'There was an error deserializing the object of type Tridion.ContentManager.Data.IdentifiableObjectData. Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 3, position 23.'. Please see InnerException for more details. at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(Unknown Source) at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(Unknown Source) at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source) at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(Unknown Source) at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(Unknown Source) at com.sun.proxy.$Proxy48.create(Unknown Source)
How can I fix this problem?
html
parameter? My guess is that it is containing an XML declaration, while you seem to assume it as an HTML/XML element only.