RTF Text field is Adding Namespace Tags to HTML Items

<P>This is Text</p>

and SDL is converting it into

<p xmlns="http://www.w3.org/1999/xhtml">This is Test</p>

and need help to remove following namespace tag from output.

So far i have created a TBB to replace text using

 var fields = new ItemFields(cp.Content, cp.Schema);
            foreach (var field in fields)
                if (field is XhtmlField)
                    XhtmlField xhtmlField = field as XhtmlField;
                    xhtmlField.Value = TemplateUtilities.ResolveRichTextFieldXhtml(xhtmlField.Value);

but still output contains same Field value and need a way to replace this output.

Update: I am able to delete Namespaces using XML methods,but receiving errors during DD4T-Generate dynamic component Presentation TBB.Following TBB will remove Namespace tags from DD4T Output.

Final Solution:

                Item item = package.GetByName(Package.OutputName);
                if (item != null)
                    string output = item.GetAsString();
                    //Following regex replace xmlns strings from output.
                    string strXMLPattern = "\\s+xmlns\\s*(:\\w)?\\s*=\\s*\\\\\"(?<url>[^\\\"]*)\\\\\"";
                    var matchCol = Regex.Matches(output, strXMLPattern);
                    foreach (var match in matchCol)
                        output = output.Replace(match.ToString(), "");
                    package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.String, output));
  • Welcome to Tridion StackExchange
    – Velmurugan
    Commented Sep 1, 2020 at 20:31
  • For clarity: the content/value of a Rich Text Field is XHTML. That is: XML in the XHTML namespace. You can’t change that (removing the namespace declaration would make it just XML, but not XHTML). Removing the namespace declarations is typically done in template code (assuming the templates render HTML instead of XHTML). See the Answers. Commented Sep 2, 2020 at 6:45

3 Answers 3


Welcome, Mahesh. Try the Convert XML to XHTML Template Building Block, which is separate from Default Finish Actions.

Otherwise run Template Builder to confirm how your Output changes for each TBB.


Your Regex looks overly complex, but does seems to work fine on plain XHTML.

However, if you're using DD4T, the XHTML will be embedded in JSON. As a result, the double quotes will be escaped (preceded by a backslash), in which case the Regex no longer works.

Just obtain the DD4T JSON and test it using an online Regex tester, for example: http://regexstorm.net/tester

  • Thanks for information.I am able to remove namespaces by following your suggestion. Commented Sep 3, 2020 at 15:46
  • Normally, you would use DD4T not only on the content management side but also on the delivery side. The DD4T factories used in your web application will remove the namespaces as well. If you don't use DD4T on the delivery side, a regex is indeed a simple solution.
    – Quirijn
    Commented Sep 3, 2020 at 18:42

Refer to this article might help some of the answers - Unwanted Namespaces in Rendered Output

Alternatively, you could also use XmlDocument to load the XHTMLValue to process to remove the Namespaces.


    private String RemoveNameSpace(String xml)
        if (!String.IsNullOrEmpty(xml))
            XmlDocument xdoc = new XmlDocument();
            return xdoc.SelectSingleNode("/root").InnerXml;
            return String.Empty;

I hope it helps

  • Removing namespace creating issue during DD4T -Generate dynamic component presentation TBB Step. Commented Sep 2, 2020 at 16:41
  • @MaheshMajeti Are you looking for custom TBB to handle the rich text value to removing namespace? what exactly are you trying to do?
    – Velmurugan
    Commented Sep 2, 2020 at 20:00
  • @Velmurugan-Yes.Currently we are using DD4T TBB for components,I am trying to implement custom tbb to remove these namespace tags from output. Added remove namespace custom TBB before DD4T TBB to remove namespace tags from component,But ran into an issue as DD4T tbb has dependency on that namespace tag.So trying to remove these tags from final DD4T TBB Output.Let me know is there any option to do the same. Commented Sep 2, 2020 at 22:11

Your Answer

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

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