當在解析XML飼料,我正在從內容的標記文字,就像這樣:替換HTML實體(例如’)與字符等效解析XML飼料
政府授予的資金用於重大翻新項目繼續在St Eunan ’ s學院進行。這是除了上個月’的宣佈,其預製件的授予將被永久性住宿所取代。最新的撥款將允許對學校的一部分進行大修,以允許爲類別–新的住宿項目還將涉及屋頂維修,安裝除塵系統,新科學室配件和安裝報警器。多尼戈爾副喬·麥克休說,信用證必須去學校’董事會管理的
反正有沒有輕鬆地與他們的性格等價物例如,省略號等替換這些特殊字符(即HTML實體)?
編輯:
Ti.API.info("is this real------------"+win.dataToPass)
回報:(添加爲了清楚換行符)
[INFO][TiAPI (5437)] Is this real------------------Police in Strabane are
warning home owners and car owners in the town to be vigilant following a recent
spate of break-ins. There has been a number of thefts from gardens and vehicles
in the Jefferson Court and Carricklynn Avenue area of the town. The PSNI have
said that residents have reported seeing a dark haired male in and around the
area in the early hours of the morning. Local Cllr Karina Carlin has been
monitoring the situation – she says the problem seems to be getting
worse…….
我external.js文件低於即其僅顯示上述文本中的一個:
var win= Titanium.UI.currentWindow;
Ti.API.info("Is this real------------------"+ win.dataToPass);
var escapeChars = { lt: '<', gt: '>', quot: '"', apos: "'", amp: '&' };
function unescapeHTML(str) {//modified from underscore.string and string.js
return str.replace(/\&([^;]+);/g, function(entity, entityCode) {
var match;
if (entityCode in escapeChars) {
return escapeChars[entityCode];
} else if (match = entityCode.match(/^#x([\da-fA-F]+)$/)) {
return String.fromCharCode(parseInt(match[1], 16));
} else if (match = entityCode.match(/^#(\d+)$/)) {
return String.fromCharCode(~~match[1]);
} else {
return entity;
}
});
}
var newText= unescapeHTML(win.datatoPass);
var label= Titanium.UI.createLabel({
color: "black",
//text: win.dataToPass,//this works!
text:newText,//this is causing an error
font: "Helvetica",
fontSize: 50,
width: "auto",
height: "auto",
textAlign: "center"
})
win.add(label);
避免在刪除它們?用它們的字符替換它們? - 你想用繩子做什麼? –
@ Alex K.是的替換他們的字符等值。我將它們作爲文本顯示在窗口上 – user2363025
@ Alex K.我意識到自定義查找和替換功能可以做到這一點,但我懷疑是否有另一種方式,因爲我必須知道所有可能出現的特殊字符 – user2363025