10

I create some hyperlinks in RTF field of a component. The type of the hyperlink is "other". It looks like below in the source tab of the field.

<a href="tel://{telephone number}">linkText</a>

but in the publishing output it's converted to : <a href="tel://{telephone number}" xmlns="http://www.w3.org/1999/xhtml">linkText</a> adding the namespace "http://www.w3.org/1999/xhtml".

The Question is :

  1. If i don't want the namespace in the output, what are the options? I know I can do a find-replace in templating. But searching for a better approach.
  2. What could be the adverse effects if i remove the namespace other than html version compatibility?

UPDATE: I've tried using the "Default Finish Actions" TBB in CT and PT.

2
  • Hi Saurabh - do you happen to have nested <p> tags? I've sometimes seen the cleanup not happen as the template outputs a surrounding <p> tag and the RTF content is surrounded in same - I suspect the inner isn't 'cleaned' as it's not valued XHTML? Feb 16, 2015 at 19:53
  • Yeah, this was the case really as @John mentioned in the answer. Feb 17, 2015 at 8:18

3 Answers 3

11

The reason that you get the namespace is because DWT outputs XHTML by default.

I've usually just done the cleanup using a custom "find and replace" TBB as you've mentioned in your question. However, I believe Default Finish Actions has a TBB called Cleanup Template which cleans out the namespaces. So try this first.

5
  • Using the "Default finish actions", which includes the cleanup template than Nick mentions, will remove the namespace
    – Nuno Linhares
    Feb 16, 2015 at 13:51
  • Thanks guys, We are using "cleanup Template" in our custom finish actions already. I've tried using default finish actions as well but no luck. It still renders the namespaces. I have tested it in template builder and actual publish. Feb 16, 2015 at 15:17
  • 1
    I believe those TBBs run against Output--double check there's nothing else adding or replacing Output in the package. There's also a TBB to convert from XML to HTML, which does the following: "Convert XML to HTML tries to convert the XML of the package item called Output into HTML. Specifically, it removes any XHTML namespace declaration and converts all empty XML elements (for example, <br/> ) to empty HTML elements ( <br> )." Feb 16, 2015 at 16:48
  • 1
    If you find yourself at an impasse, and wind up writing something for yourself it might be worth looking at using the HTMLAgilityPack if you intend on doing any other manual HTML manipulation. .NET's standard XML libraries are inadequate in dealing with any HTML except XHTML (and even then, there's no guarantee that's well-formed XHTML in the first place), and regexing through it can be a really large pain. Feb 16, 2015 at 18:39
  • 1
    You don't need to regex or use an HTML parser. An RTF contains a well-formed XML fragment in the XHTML namespace. You can use standard XML techniques, although you'll need to wrap it in a containing element to parse it as an XML document. Feb 16, 2015 at 19:47
5

I've been looking at this issue today with Saurabh, he's pulling in content from a component into the middle of a <p> tag. when the content (which is from an RTF) contains a <p> - the result is a nested

this isn't valid so the default building block doesn't resolve and clean it up.

We've dropped in some code in our tbb to clean this up and the problem is resolved.

2

There is a static method ResolveRichTextFieldXhtml(string inputXhtml) in TemplateUtilities class.

Which could be used to resolve the rich text field value. it converts the links to the format that link resolver TBB expects and also removes the unwanted namespaces as summarized here.

The class TemplateUtilities resides in Tridion.ContentManager.Templating.dll.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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