5

I have found an issue when using CoreService to read componentData.Content: All the non-breaking spaces   are missing.

This could cause issue if the data is saved back to Tridion.

Example:

Original Content: <p>&#160;</p>

Content read from Coreservice: <p> </p>

Is the any solution to fix this issue?

  • I'm not sure I understand where the problem is, since that's the same character. Does it affect content in any way? – Nuno Linhares May 1 '13 at 20:15
  • Can you explain what the error is here? – johnwinter May 1 '13 at 20:19
  • 1
    If you really need the &#160; you could load componentData.Content into XmlDocument, XDocument, XElement etc.. and then encode the inner text of desired nodes. Like everyone else, I am confused why this is an issue? – Chris Morgan May 1 '13 at 20:32
  • &#160; is xml representation of &nbsp; but when you read from Tridion coreservice it is " " blank space, so it is not easy to tell which one is real blank space... – Lucas Liu May 1 '13 at 20:34
  • 1
    like HTML, not every blank space is &nbsp; so you cannot convert every blank space to &#160; missing &#160; means missing real value of the content – Lucas Liu May 1 '13 at 20:42
9

Are you sure the character you see as space isn't actually the non breaking space character instead?

When running the following program on Tridion 2013:

class Program
{
    static void Main(string[] args)
    {
        SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2012");

        try
        {
            ComponentData component = (ComponentData)client.Read("tcm:1-38", new ReadOptions());
            XDocument dom = XDocument.Parse(component.Content);
            string fieldValue = dom.Descendants().First(e => e.Name.LocalName == "RichTextField").Value;

            Console.WriteLine(fieldValue);
            foreach (char c in fieldValue)
            {
                Console.Write(" {0}", (int)c);
            }
            Console.WriteLine();
        }
        finally
        {
            if (client.State == CommunicationState.Faulted)
            {
                client.Abort();
            }
            else
            {
                client.Close();
            }
        }
    }
}

I get the following result:

a b
97 160 98

So even though it looks like I just got a space, the non breaking character is preserved. As a general rule, never process the XML returned direcrly as a string source - run it through something like the XDocument, an xml reader or similar that will let you access the actual content in the XML format consistently no matter the "syntax" used to represent the content.

| improve this answer | |
  • component.Content is string type, so this also works: foreach (char c in component.Content) { (int)c; } if – Lucas Liu May 9 '13 at 2:12

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.