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[[&&]]></someTag>
Is there any way to prevent wrapping of "&&" with CDATA?
Please sign in to leave a comment.
IntelliJ IDEA 13 and later has com.intellij.psi.xml.XmlTagValue#setEscapedText
Yann,
Thank you for your reply. Is there a way to achieve that in IDEA 12?
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); } }