0

I am trying to create Components using Tridion Core Service. I want to insert raw HTML content on Source tab of Rich Text Field. Refer the attached screenshot which manually I modified, the same thing I want using Core Service -

Rich Text Field

Using normal content I can able to create the components. But while I am providing HTML content, then I am getting error.

Could someone please help me!!. Thanks in advance.

I am using the below code -

public  string HandleXhtmlFieldDefinitionData(ItemFieldDefinitionData field, DataRow row, StringBuilder sb)
        {
            string field_Name = string.Empty;
            string field_Value = string.Empty;

            field_Name = field.Name;
            field_Value = row[field_Name].ToString();
            string[] field_Values = field_Value.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string value in field_Values)
            {
                sb.Append("<" + field_Name + ">" + value.Trim() + "</" + field_Name + ">");
            }

            return sb.ToString();
        }

While I am providing the normal content then I am getting no error. But while I am providing HTML snippet then I am getting the below error -

XML validation error. Reason: The element 'description' in namespace 'uuid:bdeed3aa-7a94-493d-962c-128505e6022e' has invalid child element 'div' in namespace 'uuid:bdeed3aa-7a94-493d-962c-128505e6022e'. List of possible elements expected: any element in namespace 'http://www.w3.org/1999/xhtml'.
  • Can you show the code you use to achieve this? – Rick Pannekoek Apr 1 at 19:09
  • Hi @RickPannekoek, please refer the above information. – Sudip Ghorai Apr 6 at 8:09
2

When dealing with Rich Text fields the best approach is to convert HTML to XHTML using Tidy.NET. That also ensures your content is valid Xhtml. Nuno already described the process in this blog. Check this and implement it accordingly.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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