Results 1 to 2 of 2

Thread: [RESOLVED] Removing particular XML elements with SimpleXML

Hybrid View

  1. #1
    Join Date
    Jan 2010

    resolved [RESOLVED] Removing particular XML elements with SimpleXML

    Hello everyone.

    I am trying to edit an element on a XML file with SimpleXML, and as far as I am concerned I have to remove the old one and then add the new one. First of all, my XML file is like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <Placemark id="1000"><!-- children elements --></Placemark>
    <Placemark id="1001"><!-- children elements --></Placemark>
    <Placemark id="1002"><!-- children elements --></Placemark>
    I load the XML like this:
    PHP Code:
    $xml simplexml_load_file($xmlfile) or die("Αρχείο XML δε βρέθηκε");
    Now i find the <Placemark> element with the id attribute I want like this:
    PHP Code:
    foreach ($institutions as $institution)  {
    if (
    $institution['id']==$id) {
    $current_uni $institution;

    What do I have to do to remove this particular element?

    Thank you in advanced.

  2. #2
    Join Date
    Jan 2010
    No worries, got it. Found out that I had to use DOM, simpleXML does not remove stuff.

    Just for anyone interested:

    PHP Code:
    $id $_POST["id"];

    $xml->Placemark as $uni)
    $uni['id'] == $id) {
    if ((
    $xml->asXml($xmlfile)) == 1)
    'All good';
    'Woopsie, try again'

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles