带有php的动态xml


dynamic xml with php

试图编写一个XML文件,该文件填充了从目录列表中提取的信息,但我不知道如何让createElement薄荷糖更好地处理动态内容。

我很想像动态表一样在标记中进行硬编码,然后将整个输出发布到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>

您可以使用urlender()函数来不破坏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考虑了从第191行到第200行的HTML标记标签项目
文件路径
文件宽度
文件重量
文件标题
文件描述
文件映像
featured_image
featured_or_not
被认为是XML标记,应该进行解析,而不是在HTML正文中转储XML。如果您希望网站的访问者能够访问XML并按照他/她希望的方式解析XML,那么您应该将XML标记转储到文件中,但如果没有HTML标记,则使用诸如和之类的自定义标记,如果用户想从中生成HTML表,或者包括"GenerateList"的编码输出并打印,则应该解析XML,但通过这种方式,我在上面提到的XML标记将为您提供HTML表的预期结果,并用TD代替它们来表示HTML表中的单元格。希望它能帮助

发现需要使用loadXML而不是od-aendchild 的问题