• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading From XML instead of database?

#1
[eluser]saidbakr[/eluser]
Hello,

I need to know how reading a local, or remote, server xml file and using its data instead of database? For example,
Code:
<xml>
<item>
<item_id>1</item_id>
<item_title>First title</item_title>
<item_content>First one content blah blah..</item_content>
<item_author>John Loe</item_author>
</item>
<item>
<item_id>2</item_id>
<item_tite>and so on....

How could I use CI to read this XML file? and what are suitable to do this task, a helper or a plugin? and where could I able to find pre-made such plugins and helpers for CI?

#2
[eluser]saidbakr[/eluser]
Hello

I found the solution in XML Library inside the CI Wiki. Everything goes well but I need to add &lt;![CDATA[ ]]> to the text content to disallow parsing of HTML tags inside the text here is an example of the xml:
Code:
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<posts xmlns:h="http://www.w3.org/TR/html4/">
<item>
<id>0</id>
&lt;title&gt;Title Num 1&lt;/title&gt;
<content>&lt;![CDATA[<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris quis tellus id mauris imperdiet tincidunt. Donec euismod rhoncus urna, ut malesuada sapien vestibulum ut. Ut pretium neque quis velit vehicula elementum rutrum risus dapibus. Vivamus dictum felis ut libero aliquam sit ed non neque auctor velit ultrices vestibulum. Cras tristique consectetur neque non commodo. Praesent ligula justo, pellentesque sit amet venenatis at, dictum sit amet purus. Vivamus ultrices adipiscing erat, a rutrum dolor mattis in.
</p>
<p>
Aenean volutpat pellentesque mauris, sit amet lobortis odio aliquam at. Pellentesque ac ligula id diam cursus dictum. Cras sed justo dui. Vestibulum vitae orci leo. Cras imperdiet tristique adipiscing. Pellentesque orci dolor, consequat sed dictum et, ornare in turpis. Donec sit amet arcu vel lectus coeugiat augue. Donec interdum tincidunt elit vitae venenatis.
</p>
]]>
</content>
<dated>2009-09-10</dated>
<author>Said Bakr</author>
<comments>5</comments>
</item>
<item>
<id>1</id>
&lt;title&gt;Title Num 2&lt;/title&gt;
<content>&lt;![CDATA[
<p>
Morbi ...

However, The generated array from the xml parser is not clean enough it needed some modification to get the data in the view file to be something like &lt;?php echo $item['title'][0] ?&gt; and the index [0] should be found inside the loop, i.e there are no 1,2, 3 etc it only 0.

Thank you all


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.