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());
LinkToSchemaData lstd=new LinkToSchemaData();
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?

  • 1
    from the code sample which you specify, I would really like to see what is the value of the html parameter? My guess is that it is containing an XML declaration, while you seem to assume it as an HTML/XML element only. Commented May 22, 2014 at 13:11
  • @BartKoopman +1 - the exception message is pretty explicit about what the problem is.
    – Ant P
    Commented May 22, 2014 at 14:07

3 Answers 3


By the sample you put there it doesn't look like your component's XML is well formed (but that could just a mistake copy/pasting here).

I would recommend that you create a component first "manually" in the CM, then look at it's real XML, then try to duplicate it in your app.

If you're using Tridion 2011 (or 2013 with Legacy Pack), you can check the component's XML by opening Internet Explorer and typing the tcm ID of the component as the address (must be on the server itself). If you're on 2013 and don't have the Legacy Pack installed you should do a CoreService.Read("tcm:1-23") and check the response for the actual XML of the component. Looking at the source tab in Tridion will not give you the exact XML you need, it's a simplified version of it.

Good luck

  • 2
    After correcting your post (it's really not that hard to format code in Stack Exchange), it looks like you possibly have valid XML - still, try to compare with the XML written by Tridion, and find the differences. The Tridion UI uses the same API as you (CoreService).
    – Nuno Linhares
    Commented May 22, 2014 at 12:58

Your HTML seems to be non-compliant. It should have a Namespace declaration in the tags.

If you have any issue using XML, you can use answer from frank in the Stack Overflow post How to set content to a component without loading XML in SDL Tridion using core services?.


You can find working examples of how to do this on the Tridion practice web site. Check these out:



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.