2012-07-12 76 views
0

試圖編寫一個XML文件填充從目錄列表中獲取的信息,但我無法弄清楚如何獲得createElement menthods與動態內容很好玩。動態XML與PHP

我很想試試像動態表一樣的標籤中的硬代碼,然後把整個輸出結果發佈到xml文件中,但我不知道如何將預格式標籤放入xml中。

我的XML需要被格式化爲這樣

<CONTENT> 
    <GALLERY name="**HARDCODED DATA**"> 
     <CATEGORY name="**HARDCODED DATA BASED FROM DIRECTORY SEARCH 1**" desc="**HARDCODED DATA BASED FROM DIRECTORY SEARCH 1**" thumb="**HARDCODED DATA BASED FROM DIRECTORY SEARCH 1**"> 
      <ITEM> 
       <file_path>**dynamic content from directory search**</file_path> 
       <file_width>**HARDCODED**</file_width> 
       <file_height>**HARDCODED**</file_height> 
       <file_title>**dynamic content from directory search**</file_title> 
       <file_desc>**Loaded from a seperate txt file, index to match with the index of the dir file**</file_desc> 
       <file_image>**Loaded from a seperate txt file, index to match with the index of the dir file**</file_image> 
       <featured_image>**Loaded from a seperate txt file, index to match with the index of the dir file**</featured_image> 
       <featured_or_not>**Loaded from a seperate txt file, index to match with the index of the dir file**</featured_or_not> 
      </ITEM> 
****loop through for next ITEM**** 
     </CATEGORY> 
****start next category from secody directory search content**** 
    </GALLERY> 
****start gallery 2 and 3 here, same format at gallery 1**** 
</CONTENT> 
+0

請,如果你想要更多的幫助你添加PHP代碼所需的問題。 – 2012-07-13 16:58:15

+0

有沒有鏈接進一步下來評論的全部來源,在這裏它再次http://maskedriders.info/Sources/Power%20Rangers/webplayer.phps – NekoLLX 2012-07-22 23:21:04

回答

1

你可以使用進行urlencode()函數不分手XML

echo urlencode("<table><tr><td>Encoded data</td></tr></table>"); 

,你會得到

%3Ctable%3E%3Ctr%3E%3Ctd%3EEncoded+data%3C%2Ftd%3E%3C%2Ftr%3E%3C%2Ftable%3E 

嘗試解碼與urldecode()你會得到

<table> 
<tbody> 
    <tr> 
    <td>Encoded data</td> 
    </tr> 
</tbody> 
</table> 

編輯我想我找到你的問題,是在 「生成列表」 標籤

TR
TD
AR考慮HTML標記,而從線191至線200 項
FILE_PATH
file_width
file_height
FILE_TITLE
file_desc
file_image
featured_image
featured_or_not
被認爲是XML標記,應該被解析而不是在HTML主體中轉儲XML。 如果您希望您的網站的訪問者有權訪問XML並解析,他/她希望XML只是將XML標記轉儲到文件中,但如果沒有HTML標記,則應使用自定義標記(如and和user)解析XML如果他想生成一個HTML表格,或者包含「GenerateList」的編碼輸出並且打印BUT,那麼我會提到上面的XML標籤會給你期望的HTML表格intead替換它們的TD代表HTML表格中的一個單元格。 希望它幫助

+0

將與像 custome標籤一起工作,雖然邏輯上,我可以寫所有這對一個單一的pgp變量如何將該變量傳遞給xml解析器createElement()與一個巨大的代碼源而不是一個標籤一起工作? – NekoLLX 2012-07-13 17:48:15

+0

將在XML標記,只要標籤名稱是有效的工作(可能是錯字在一個),你可以在編碼值作爲參數傳遞給 的createElement(「標籤」,urlecode($ HTML_MARKUP)); 來解析,簡單地... ..解析XML和在你希望被「硬編碼」的標籤/屬性只是使用urldecode()從編碼值檢索HTML標記。 – Gntem 2012-07-13 18:50:05

+0

所以最終結果看起來像是 $ htmlvalue對不對? – NekoLLX 2012-07-13 19:09:08

0

發現使用loadXML的,而不是OD apendchild