ColdFusion循环遍历xml转义xml标签 [英] ColdFusion loop over xml escape xml tags

查看:87
本文介绍了ColdFusion循环遍历xml转义xml标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,在XML上循环很容易.在ColdFusion中,一切都很容易...但是,当我循环并获取值时,我同时获得了值和XML标记.

Yes, looping over XML is easy. Everything is easy in ColdFusion ... BUT when I loop and get values I get both values and XML tags.

例如,在带有国家/地区的XML字符串中,我应该只会得到"Australia".但是,我得到了:

For example in an XML string with countries, I should be getting just "Australia". However, I am getting:

<!--?xml version="1.0" encoding="UTF-8"?-->
<country>Australia</country>

当然,我只能执行reReplace,所以我只得到值而没有标签.但是,如果我得到一个包含大量数据的XML,则我不想遍历所有内容并清理每个XML项以获得所需的信息.有人对此有任何解决方法吗?

Of course, I can just reReplace so I get only the value and none of the tags. However, if I get a XML with lots of data, I don't want to loop over everything and clean each XML item in order to get what I want. Does anyone have any workaround for that?

PS:这是有效的XML

PS: It is a valid XML

这是代码:

<cfset feedResult=XmlParse(grc.filecontent)>  
 <cfloop array="#feedResult.content.states.state#" index="kl">
     <tr>
        <td>
            #kl.st#
        </td>
        <td>
            #kl.country#
        </td>
      </tr> 
  </cfloop>

推荐答案

您需要使用xmlText来获取节点的值,即

You need to use xmlText to get the value of a node i.e.,

 <cfset feedResult=XmlParse(grc.filecontent)>  
 <cfloop array="#feedResult.content.states.state#" index="kl">
     <tr>
        <td>
            #kl.st.xmlText# <!--- nodeName.xmlText --->
        </td>
        <td>
            #kl.country.xmlText# <!--- nodeName.xmlText --->
        </td>
      </tr> 
  </cfloop>

这篇关于ColdFusion循环遍历xml转义xml标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆