Prevent CDATA addition to XmlTagValue.setText

I want to set value of xml tag to value of a string "&&"
((XmlTag)tag).getValue().setText("&&")
However I endup with escaped value:
<someTag><[CDATA[[&amp;&amp;]]></someTag>

Is there any way to prevent wrapping of "&amp;&amp;" with CDATA?

3 comments

IntelliJ IDEA 13 and later has com.intellij.psi.xml.XmlTagValue#setEscapedText


0

Yann,
Thank you for your reply. Is there a way to achieve that in IDEA 12?

0

IDEA 13 implementation:

 
public void setEscapedText(String value) {
  setText(value, true);
}

private void setText(String value, boolean defaultPolicy) {
  try {
    XmlText text = null;
    if (value != null) {
      final XmlText[] texts = getTextElements();
      if (texts.length == 0) {
        text = (XmlText)myTag.add(XmlElementFactory.getInstance(myTag.getProject()).createDisplayText("x"));
      } else {
        text = texts[0];
      }
      if (StringUtil.isEmpty(value)) {
        text.delete();
      }
      else {
        if (defaultPolicy && text instanceof XmlTextImpl) {
          ((XmlTextImpl)text).doSetValue(value, new DefaultXmlPsiPolicy());
        } else {
          text.setValue(value);
        }
      }
    }

    if(myElements.length > 0){
      for (final XmlTagChild child : myElements) {
        if (child != text) {
          child.delete();
        }
      }
    }
  }
  catch (IncorrectOperationException e) {
    LOG.error(e);
  }
}
0

Please sign in to leave a comment.