[英]Coldfusion XML Replace
不知道这是否是合法操作。
我有一个使用Coldfusion读取的xml文档。
如果您具有以下条件:
<tag1>
This is text <tag2>and this is highlighted text</tag2> which is in the middle of more text
</tag1>
我可以将所有tag1放入一个变量中,然后对该变量进行替换以使用一个类将tag2更改为html以便突出显示吗?
或者,还有更好的方法?
解:
将tag1节点及其所有子标记变成字符串。
<cfset x = #tag1.xmlChildren[x]#>
将标记2替换为Need html标记。
<cfset x = #Replace(x,"<tag2>","<mark>","ALL")#>
<cfset x = #Replace(x,"</tag2>","</mark>","ALL")#>
将字符串解析回xml。
<cfset x = XmlParse(#x#)>
放出已解析的xml。
<cfoutput>#x.tag1.xmlText#</cfoutput>
<tag1>
<![CDATA[
This is text <tag2>and this is highlighted text</tag2> which is in the middle of more text
]]>
</tag1>
这将在此处将其添加为字符串,而无需转义任何内容。 它将被视为字符串,而不是XML结构的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.