Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 170551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:49:42+00:00 2026-05-11T12:49:42+00:00

I was wondering how i should go about writing an XML data layer for

  • 0

I was wondering how i should go about writing an XML data layer for a fairly simple php web site. The reasons for this are:

  1. db server is not available.
  2. Simple data schema that can be expressed in xml.
  3. I like the idea of having a self contained app, without server dependencies.
  4. I would possibly want to abstract it to a small framework for reuse in other projects.

The schema resembles a simple book catalog with a few lookup tables plus i18n. So, it is quite simple to express.

The size of the main xml file is in the range of 100kb to 15mb. But it could grow at some point to ~100mb.

I am actually considering extending my model classes to handle xml data. Currently I fetch data with a combination of XMLReader and SimpleXml, like this:

public function find($xpath){                  while($this->xml_reader->read()){          if($this->xml_reader->nodeType===XMLREADER::ELEMENT &&             $this->xml_reader->localName == 'book' ){               $node = $this->xml_reader->expand();             $dom = new DOMDocument();             $n = $dom->importNode($node, true);             $dom->appendChild($n);             $sx = simplexml_import_dom($n);                // xpath returns an array              $res = $sx->xpath($xpath);              if(isset($res[0]) && $res[0]){                  $this->results[] = $res;                                     }     }      return $this->results; } 

So, instead of loading the whole xml file in memory, I create a SimpleXml object for each section and run an xpath query on that object. The function returns an array of SimpleXml objects. For conservative search I would probably break on first found item.

The questions i have to ask are:

  1. Would you consider this as a viable solution, even for a medium to large data store?
  2. Are there any considerations/patterns to keep in mind, when handling XML in PHP?
  3. Does the above code scale for large files (100mb)?
  4. Can inserts and updates in large xml files be handled in a low overhead manner?
  5. Would you suggest an alternative data format as a better option?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:49:42+00:00Added an answer on May 11, 2026 at 12:49 pm

    If you have a saw and you need to pound in a nail, don’t use the saw. Get a hammer. (folk saying)

    In other words, if you want a data store, use a data-base, not a markup language.

    PHP has good support for various database systems via PDO; for small data sets, you can use SQLite, which doesn’t need a server (it is stored in a normal file). Later, should you need to switch to a full-featured database, it is quite simple.

    To answer your questions:

    1. Viable solution – no, definitely not. XML has its purposes, but simulating a database is not one, not even for a small data set.
    2. With XML, you’re shuffling strings around, all the time. That might be just bearable on read, but is a real nightmare on write (slow to parse,large memory footprint, etc.). While you could subvert XML to work as a data store, it is simply the wrong tool for the job.
    3. No (everything will take forever, if you don’t run out of memory before that).
    4. No, for many reasons (locking, re-writing the whole XML-string/file, not to mention memory again).

    5a. SQLite was designed with very small and simple databases in mind – simple, no server dependencies (the db is contained in one file). As @Robert Gould points out in a comment, it doesn’t scale for larger applications, but then

    5b. for a medium to large data store, consider a relational database (and it is usually easier to switch databases than to switch from XML to a database).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 140k
  • Answers 140k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you really need to make your example a singleton… May 12, 2026 at 7:53 am
  • Editorial Team
    Editorial Team added an answer Of course, I can't store an associative array directly in… May 12, 2026 at 7:53 am
  • Editorial Team
    Editorial Team added an answer Check out the Blog tutorial on the CakePHP website. That's… May 12, 2026 at 7:53 am

Related Questions

I've just recently started learning HTML/CSS and I've been trying to teach myself sound
I am making an app (asp.net/c#) that will autosuggest a couple fields that users
I was wondering what some of the best practices were around logging and logging
I was wondering what's the best practise for serving a generated big file in

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.