开发者

xml - fetch first 160 chars of a particular node

We have this xml (shortened and simplified for this question), returned to our coldfusion app, where it is parsed out and used in a news roller:

<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>

However, initially we only want to return the first 160 characters of the content. We don't want to drag the several thousand chars down to the application, THEN parse out only the first 160 chars. We need to XML pulled i开发者_JAVA百科nto the app with only the first 160 chars, then work with that xml.

What would be the easiest way to do this?

Thanks in advance, Paul


Given that something is going to have to trim the content to 160 characters, it may well make sense to have ColdFusion do it, as it's really a presentation concern. Your underlying service (DB, Web Service call, whatever) can have a simpler API which does return all the content and your presentation code in the CF can trim it down to suit.

It's also worth considering whether the getting of the XML really would be much more efficient by only getting the first 160 characters of the content. If you're getting the data over the network, the extra content may all fit into the same number of packets as the trimmed version. You could run WireShark to measure the difference between approaches to see what the effect is.

If you can post a bit more detail about where the data is coming from , that would help a lot.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜