• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using xml files for a web project.

#1
The main question here is the following,
"Is it safe - ok - faster - lighter for the website (call it as you wish) to use an XML from server file or url directly and not storing them in the db, in order to get website entries?"

E.g.:
Let's say we have a website with multiple users in it and some of them having some blog posts. Is it ok and the most important, safe to use an XML to parse the data?


P.S.: I couldn't find any related subjects about this so i thought that it would be a good discussion subject for some newbies (like me Tongue Tongue Big Grin )
Thanks!

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply

#2
You can't really sort or search that data, so I would not store it that way.
Reply

#3
I have used XML to store "website" data for 20+ years. I don't make it directly accessible, but instead have a controller/servlet which retrieves it on the server, from a not-public-facing location, and then I typically render it as HTML in some fashion. I started this practice back when servers weren't as capable, and running a databse engine alongside your web server was considered excessive resource consumption. I switched much of my work to RDBs 10 years ago, but am now switching back to XML & markdown for content, as I find it easier to edit.

I do have some apps which store XML documents as columns in an RDB, but the extra care, encoding & validation led me away from that practice. I even had a couple of apps which stored XHTML in an RDB column, and then carefully dished those for in-browser editing with redactor - not the safest practice.

As for lighter or faster, however you measure those, I was working at one point with a 20,000 "record" XML document, with no noticeable lag dishing pages based on processing that.
Reply

#4
@jreklund ... XPath is your sorting & searching friend, as well as XSLT serverside! SimpleXML has xpath capabilities. I haven't played with XSLT inside PHP, so can't comment on how appropriate it is.
Reply

#5
(03-07-2019, 03:53 PM)ciadmin Wrote: I have used XML to store "website" data for 20+ years. I don't make it directly accessible, but instead have a controller/servlet which retrieves it on the server, from a not-public-facing location, and then I typically render it as HTML in some fashion. I started this practice back when servers weren't as capable, and running a databse engine alongside your web server was considered excessive resource consumption. I switched much of my work to RDBs 10 years ago, but am now switching back to XML & markdown for content, as I find it easier to edit.

I do have some apps which store XML documents as columns in an RDB, but the extra care, encoding & validation led me away from that practice. I even had a couple of apps which stored XHTML in an RDB column, and then carefully dished those for in-browser editing with redactor - not the safest practice.

As for lighter or faster, however you measure those, I was working at one point with a 20,000 "record" XML document, with no noticeable lag dishing pages based on processing that.

So let's say we have an XML file with data like "Post image", "Post title", "Post description" etc.. etc.. 
I made a test a couple of days ago and the result was fine.
Here's the example controller:
Code:
public function xmlview(){
$data['title'] = 'XML File';
$file = base_url('assets/xml/test.xml');
$xml = simplexml_load_file($file);

foreach($xml->children() as $child) {
  $data['items'][] = array(
   'title' => $child->TITLE,
   'year' => (int)$child->YEAR
  );
}

$this->load->view('templates/header', $data);
$this->load->view('pages/xmlview', $data);
$this->load->view('templates/footer', $data);
}

Would you suggest something like that?

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply

#6
Almost ... if base_url('assets/...') is publically accessible, you are exposing your data, which is not good.
A better practice is to map your document root to your "public" folder, put index.php inside that, and to keep any XML data in a separate folder inside the project (or even elsewhere on your server).

Eg.
project
- application
- data
- XML ...
- public
- assets/images, css, etc
- index.php
- system
Reply

#7
(03-07-2019, 03:55 PM)ciadmin Wrote: @jreklund ... XPath is your sorting & searching friend, as well as XSLT serverside! SimpleXML has xpath capabilities. I haven't played with XSLT inside PHP, so can't comment on how appropriate it is.

So there are a order by functionality. Who knew! Personally I will stick to relation based database. But if it's static pages, made with markdown like you said. It could be a valid option for sure.
Reply

#8
(03-07-2019, 05:37 PM)ciadmin Wrote: Almost ... if base_url('assets/...') is publically accessible, you are exposing your data, which is not good.
A better practice is to map your document root to your "public" folder, put index.php inside that, and to keep any XML data in a separate folder inside the project (or even elsewhere on your server).

Eg.
project
- application
- data
 - XML ...
- public
 - assets/images, css, etc
 - index.php
- system

The file is stored there as an example. The real file might be in a separate folder as you mentioned or parsed from a URL. 
The main purpose was to retrieve the data from the XML and pass them to a view file in order to test speed and efficiency.

BUT, i got an XML file with up to 7000+ entries and the page was kinda slow.. (actually REALLY slow!!) What i wanted to be clarified with this discussion is that if that approach, of loading an XML file from a source (file or URL) is good for a page that contains many users and some of them might have some item "feeds" (like posts, or products or something else that can be parsed from XML).

I hope i made myself clear.

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply

#9
I think the approach is viable.
It might be possible to improve performance by separating the XML into multiple documents (one per thread? one per user?), to reduce parsing time.
It might also be possible to consider a document database (eg mongodb), though that is not directly supported in CI - it is a candidate & not fully thought out feature for CI4.
Reply

#10
(03-08-2019, 10:23 AM)ciadmin Wrote: I think the approach is viable.
It might be possible to improve performance by separating the XML into multiple documents (one per thread? one per user?), to reduce parsing time.
It might also be possible to consider a document database (eg mongodb), though that is not directly supported in CI - it is a candidate & not fully thought out feature for CI4.

Well, i will take a further look on mongoDB!

Thanks for the suggestions!

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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