xml - 获取特定节点的前160个字符

时间:2011-08-04 06:15:16

标签: xml coldfusion

我们有这个xml(缩短并简化了这个问题),返回到我们的coldfusion应用程序,在那里它被解析出来并用在新闻栏中:

<newsItems>
   <newsItem content="The International Rugby Board (IRB) has confirmed that it will take a hardline stance on any team that breaks certain parameters when an nation performs a traditional haka. This will not only apply to the All Blacks haka, but the various challenges performed by the Pacific Island teams as well for moving too close to the Black Ferns while they performed their haka. The Australian Rugby Union (ARU) paid the fine, after it was revealed by a Sydney newspaper that there was a clause in the IRB tournament rules that dictated that teams must face the haka, and remain 10 metres on their own side of the halfway line. For the record the Black Ferns won that pool match 32-5. Senior IRB officials confirmed that the regulation was in place - and had been for some time - but the fine imposed on the ARU was the first time that formal action had been taken."  extension="jpg" fileName="261840D4-CADD-6C4E-ACAF532ACFF12388" link="news/14266/IRB-confirms-haka-will-not-be-challenged" title="IRB confirms haka will not be challenged....."/>

</newsitems>

但是,最初我们只想返回内容的前160个字符。我们不想将数千个字符拖到应用程序中,然后只解析前160个字符。我们需要将XML拉入应用程序,只有前160个字符,然后使用该xml。

最简单的方法是什么?

提前致谢, 保罗

1 个答案:

答案 0 :(得分:0)

鉴于某些东西必须将内容修剪为160个字符,因此让ColdFusion这样做很有意义,因为它确实是一个表示问题。您的基础服务(数据库,Web服务调用,等等)可以有一个更简单的API,它可以返回所有内容,而CF中的表示代码可以将其修剪为适合。

通过仅获取内容的前160个字符,是否真的会更有效地获取XML也是值得考虑的。如果您通过网络获取数据,则额外内容可能都与修剪版本的数据包数量相同。 您可以运行WireShark来衡量方法之间的差异,以查看效果是什么。

如果您可以发布更多有关数据来源的详细信息,那将会有很大帮助。