2011-08-04 296 views
0

我們有這個XML(縮短和簡化了這個問題)的第160個字符,回到我們的ColdFusion的應用程序,它被解析出來,用於在新聞輥:XML - 獲取特定節點

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

最簡單的方法是什麼?

由於提前, 保羅

+0

你沒有提到XML來自哪裏。如果您希望避免使用超過160個字符,那麼您可能必須在XML的任何位置執行此操作。 – barnyr

回答

0

鑑於東西將不得不削減的內容,以160個字符,它很可能是有意義的有ColdFusion的做到這一點,因爲它是一個真正的呈現問題。你的底層服務(DB,Web服務調用,無論什麼)都可以有一個更簡單的API,它可以返回所有的內容,並且你的演示代碼可以修改爲適合。

同樣值得考慮的是,僅通過獲取內容的前160個字符來獲取XML是否真的會更有效。如果你通過網絡獲取數據,額外的內容可能都適合與修剪版本相同數量的數據包。 您可以運行WireShark來衡量方法之間的差異以查看效果是什麼。

如果您可以發佈更多關於數據來自何處的詳細信息,那將有很大幫助。