Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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=''>"+html+"</div></Body></Content>");
componentData=(ComponentData)client.create(componentData, new ReadOptions());

It has given me the following error many times. The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter 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 Source) at Source) at Source) at Source) at Source) at com.sun.proxy.$Proxy48.create(Unknown Source)

How can I fix this problem?

share|improve this question
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. – Bart Koopman May 22 '14 at 13:11
@BartKoopman +1 - the exception message is pretty explicit about what the problem is. – Ant P May 22 '14 at 14:07
up vote 3 down vote accepted

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

share|improve this answer
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 May 22 '14 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?.

share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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