Try our conversational search powered by Generative AI!

Remove New line character from XHTMLString response

Vote:
 

I am using Content Delivery API that works fine. For some reason there is a need to remove the new line characters from the xhtml string response.

Based on this article  https://world.episerver.com/documentation/developer-guides/content-delivery-api/serialization/ I tried to remove the new line character but I still see it in response.

What am I missing. Here is what I have

[ServiceConfiguration(typeof(IPropertyModelConverter), Lifecycle = ServiceInstanceScope.Singleton)]
public class CustomXhtmlStringUpdate : DefaultPropertyModelConverter
{
public CustomXhtmlStringUpdate() => ModelTypes = new List<TypeModel>
{
new TypeModel
{
ModelType = typeof(CustomHtmlStringPropertyModel), ModelTypeString = nameof(CustomHtmlStringPropertyModel), PropertyType = typeof(PropertyXhtmlString)
}
};
}

public class CustomHtmlStringPropertyModel : PropertyModel<string, PropertyXhtmlString>
{
public CustomHtmlStringPropertyModel(PropertyXhtmlString propertyXhtmlString) : base(propertyXhtmlString)
{
if (propertyXhtmlString != null)
{
Value = propertyXhtmlString.ToString().Replace(Environment.NewLine, "");
}
}
}

#222577
May 07, 2020 15:38
Vote:
 

Can you try this

Value = propertyXhtmlString.Value.ToString().Replace(Environment.NewLine, "");

I think you missed Value.

#222578
May 07, 2020 17:01
Dileep D - May 07, 2020 17:55
Just tried. Still I can see the \n.
Dileep D - May 07, 2020 17:57
Also when I inspect the propertyXhtmlString.Value. It doesn't have the new line character but the final response has it. Not sure where it is getting added.
Vote:
 

If some one needs this I resolved this using ScriptResourceHelper.RemoveNewLineWhiteSpace(content);

#222709
May 11, 2020 16:34
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.