2012-03-17 90 views
0

獲取我需要格式化的html標籤來自XML如何格式化HTML標記從XML

例如

<p><b>Location. </b> <br />Located in central Chennai, The Raintree Hotel, 
Anna Salai is connected to the airport and close to U. S. Consulate, 
Valluvar Kottam, and Anna University.<p><b>Hotel features</b> 
Other points of interest near this luxury hotel include SDAT Tennis Stadium and Kapalishvara Temple. </p><p><b>Hotel Features. </b><br />Dining options at The Raintree Hotel, Anna Salai include 2 restaurants. A swim-up bar and a bar/lounge are open for drinks. <p> 

當我從獲取使用SimpleXML PHP的XML這一數據就說明這種類型data.I的不想此生data.i需要這樣

Location 
    Located in central Chennai, The Raintree Hotel, Anna Salai is connected to the airport and close to U. S. Consulate, Valluvar Kottam, and Anna University. Other points of interest near this luxury hotel include SDAT Tennis Stadium and Kapalishvara Temple. 

Hotel Features 
    Dining options at The Raintree Hotel, Anna Salai include 2 restaurants. A swim-up bar and a bar/lounge are open for drinks. Room service is available 24 hours a day. The hotel serves a complimentary breakfast. Recreational amenities include an outdoor pool, a 

我需要的HTML格式的數據顯示在瀏覽器中沒有html標籤數據

在此先感謝

回答

0

你可以使用html-entity-decode如果您控制的HTML呈現方式。如果不是,則會暴露Cross-site scripting攻擊。

您可以通過更改xml格式來避免使用html標籤(即包含<location><description>標籤或類似標籤)。如果您從外部參與者獲得html,請嘗試自己編寫解析器以安全地提取你只需要部分。

0

格式良好的XML值分配給您的目標元素的innerHTML財產,就是他..希望這可以幫助你......

+0

我使用AJAX的jQuery喜歡的innerHTML我使用HTML ()函數在jQuery中,但它顯示相同的數據 – 2012-03-17 07:54:25

+0

'<!DOCTYPE html> 你好

'從jQuery文檔1.4中顯示html字符串的示例 – iDroid 2012-03-17 08:02:17