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

  • SEARCH
  • Home
  • 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 3693562
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:23:31+00:00 2026-05-19T04:23:31+00:00

thanks you all for helping me to learn xml+php! I want to make an

  • 0

thanks you all for helping me to learn xml+php!

I want to make an Autoincrement for the id child node.
in my createxml.php i’m the one who enter the id..
i want to be able to know what is the maxium value of all id’s and then the id=max_value++

I hope i explain my self well.

this is the events.xml file:

<events>
    <record>
        <id>1</id>
        <event>a</event>
        <eventDate>a</eventDate>
        <desc>a</desc>
    </record>
    <record>
        <id>2</id>
        <event>b</event>
        <eventDate>b</eventDate>
        <desc>b</desc>
    </record>
</events>

and this is how i adding new child nodes to the xml..

parser.php:

<?php

header("Content-type: text/html; charset=utf-8");

$record = array(
    'id' => $_POST['id'],
    'event' => $_POST['event'],
    'eventDate' => $_POST['eventDate'],
    'desc' => $_POST['desc'],
);

$doc = new DOMDocument();
$doc->load( 'events.xml' );
$doc->formatOutput = true;
$r = $doc->getElementsByTagName("events")->item(0);
$b = $doc->createElement("record");

$id = $doc->createElement("id");
$id->appendChild(
    $doc->createTextNode( $record["id"] )
);
$b->appendChild( $id );

$event = $doc->createElement("event");
$event->appendChild(
    $doc->createTextNode( $record["event"] )
);
$b->appendChild( $event );

$eventDate = $doc->createElement("eventDate");
$eventDate->appendChild(
    $doc->createTextNode( $record["eventDate"] )
);
$b->appendChild( $eventDate );

$desc = $doc->createElement("desc");
$desc->appendChild(
    $doc->createTextNode( $record["desc"] )
);

$b->appendChild( $desc );
$r->insertBefore( $b,$r->firstChild );

$doc->save("events.xml");

    header("Location: {$_SERVER['HTTP_REFERER']}");    
?>

Thanks all for helping!

  • 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. Editorial Team
    Editorial Team
    2026-05-19T04:23:31+00:00Added an answer on May 19, 2026 at 4:23 am

    Something like this, perhaps:

    $ids = array();
    foreach($doc->getElementsByTagName('id') as $id) {
        $ids[] = (int) $id->nodeValue;
    }
    $max_id = max($ids);
    

    Edit Possibly a nicer way is with XPath:

    $xpath = new DOMXPath($doc);
    $max_id = $xpath->query('//events/record[not(../record/id > id)]/id')->item(0)->nodeValue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all I want to say thanks in advance for helping me. I
First off thanks to all the users who have made my android developing adventure
Thanks,in advance I want to remove all the zero size files in specified directory,can
Again thank you to all who spend a little of their time helping me
Hey, first of all thanks for helping me out with this (probably stupid) question
First of all, thanks everyone for helping yesterday. I've managed to get my report
Thank you all for helping. Below this post I put the corrected version's of
Thanks to all that responded to my previous thread. There is still a problem
First of all thanks in advance, this has been very frustrating and I'm hoping
first of all thanks for taking your time! I'm a junior Dev, working with

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.