xml - 获取特定节点的前 160 个字符
我们有这个 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 个字符。我们需要将仅包含前 160 个字符的 XML 拉入应用程序,然后使用该 xml。
做到这一点最简单的方法是什么?
提前致谢, 保罗
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 into 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于某事必须将内容削减到 160 个字符,让 ColdFusion 来做这件事可能很有意义,因为这实际上是一个演示问题。您的底层服务(数据库、Web 服务调用等)可以有一个更简单的 API,它确实返回所有内容,并且 CF 中的表示代码可以对其进行精简以适应。
还值得考虑的是,通过仅获取内容的前 160 个字符来获取 XML 是否真的会更有效。如果您通过网络获取数据,则额外的内容可能全部放入与修剪版本相同数量的数据包中。
您可以运行 WireShark 来衡量方法之间的差异,看看效果如何。
如果您可以发布有关数据来源的更多详细信息,那将会有很大帮助。
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.