• 0

Writing and parsing XML Files with PHP


Question

For a website I need to make a very simple database of members and their information but I don?t have a database to write to. It need make a form to add new members to it so I thought using PHP and writing an XML file would be the simplest? Its not private information so im not too worried about somebody reading the xml file.

Writing something simple for example:

<member>

<name> Mr Example </name>

<type> admin </type>

<location> London </location>

<email> email@email.com</email>

</member>

Really I need some basic tutorials appending to XML files. Although Reading and parsing the file I can do, editing the file is another thing. I can set read/write permissions its just writing the code to do it!

I hope you get what I mean. I can adapt PHP code but not very good at writing it from scratch:blush:h:

EDIT: After re-googleing (if thats a word) i found this on the PHP site on appending to xml files:

$file_name="my_xml.xml";

$dom = new DomDocument();
$dom-&gt;load($file_name);

$item = $dom-&gt;createElement("item");
$title = $dom-&gt;createElement("title");
$link=$dom-&gt;createElement("link");
$titletext = $dom-&gt;createTextNode("New Title");
$title-&gt;appendChild($titletext);
$link_text=$dom-&gt;createTextNode("New Link");
$link-&gt;appendChild($link_text);
$item-&gt;appendChild($title);
$item-&gt;appendChild($link);
$dom-&gt;documentElement-&gt;appendChild($item);
$dom-&gt;save($file_name);

Edited by haisdeaks

1 answer to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I'm really happy that you're looking to apply for a role in writing articles for Neowin. We could do with more, regardless, so everyone is happy and has a story to read when ever they login to the site. https://www.neowin.net/contact/apply I look forward to reading what you have to say in the near future in one of the published articles here on Neowin. You can do it. You got this.
    • Uranus releases about 15% more energy than it receives from the Sun, according to two new papers published in the journal Monthly Notices of the Royal Astronomical Society and the journal Geophysical Research Letters. The amount of heat a planet exudes could be an indication of its age: the less heat released relative to the heat absorbed from the Sun, the older the planet is. Uranus stood out from the other planets because it appeared to give off as much heat as it received, implying it had none of its own. This puzzled scientists. Some hypothesized that perhaps the planet is much older than all the others and has cooled off completely. Others proposed that a giant collision — the same one that may have knocked the planet on its side—blasted out all of Uranus’ heat. But none of these hypotheses satisfied scientists, motivating them to solve Uranus’ cold case. https://www.sci.news/space/warmer-uranus-14079.html  
    • The reality is that it's much, much cheaper to have a single code base than rewrite and maintain everything in native frameworks for each platform. It's just sad that the most reliable technology stack for it is so heavy on resources (literally 3 times the RAM, according to the screenshots).
    • Trump Logic:  If people are talking about football team names... they won't be talking about Epstein! 🤣
  • Recent Achievements

    • Rookie
      Snake Doc went up a rank
      Rookie
    • First Post
      nobody9 earned a badge
      First Post
    • One Month Later
      Ricky Chan earned a badge
      One Month Later
    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      495
    2. 2
      Michael Scrip
      203
    3. 3
      ATLien_0
      197
    4. 4
      Xenon
      136
    5. 5
      +FloatingFatMan
      116
  • Tell a friend

    Love Neowin? Tell a friend!