Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

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?

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

3 Answers 3

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
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 May 22 at 12:58
add comment

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
add comment

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

https://code.google.com/p/tridion-practice/wiki/CreateTestContent

https://code.google.com/p/tridion-practice/wiki/Baconator

share|improve this answer
add comment

Your Answer

 
discard

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.