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 296287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:32:06+00:00 2026-05-12T06:32:06+00:00

I want to modify my xml file in PHP based on the following criteria.

  • 0

I want to modify my xml file in PHP based on the following criteria.

my xml structure look like this:

<?xml version="1.0" encoding="ISO-8859-1" ?> 

<markers>
   <marker>
      <type></type>
      <title></title>
      <address></address>
      <latitude></latitude>
      <longitude></longitude>
   <marker>
   <marker>
      <type></type>
      <title></title>
      <address></address>
      <latitude></latitude>
      <longitude></longitude>
   <marker>
</markers>

Now every time when xml going to modify, with the type attribute.

means, on first time search string == “hotels” then data related to hotels will be stored in xml file as above format.

Now when again search for hotels is done then it will remove the elements which have child element with value hotels.

and search for different query for e.g. schools is done at that time data related to the schools are appended to the xml file. with the data of the hotels.

now again search for schools is done then it will remove the element related to schools.

Thanks in advance.

  • 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-12T06:32:06+00:00Added an answer on May 12, 2026 at 6:32 am

    You can use the DOMDocument from PHP.

    You load your file and than loop trough the childNodes of the document.

    <?php
    $dom=new DOMDocument();
    $dom->load("file.xml");
    
    $root=$dom->documentElement; // This can differ (I am not sure, it can be only documentElement or documentElement->firstChild or only firstChild)
    
    $nodesToDelete=array();
    
    $markers=$root->getElementsByTagName('marker');
    
    // Loop trough childNodes
    foreach ($markers as $marker) {
        $type=$marker->getElementsByTagName('type')->item(0)->textContent;
        $title=$marker->getElementsByTagName('title')->item(0)->textContent;
        $address=$marker->getElementsByTagName('address')->item(0)->textContent;
        $latitude=$marker->getElementsByTagName('latitude')->item(0)->textContent;
        $longitude=$marker->getElementsByTagName('longitude')->item(0)->textContent;
    
        // Your filters here
    
        // To remove the marker you just add it to a list of nodes to delete
        $nodesToDelete[]=$marker;
    }
    
    // You delete the nodes
    foreach ($nodesToDelete as $node) $node->parentNode->removeChild($node);
    
    echo $dom->saveXML();
    ?>
    

    You can save your output XML like this

    $dom->saveXML(); // This will return the XML as a string
    $dom->save('file.xml'); // This saves the XML to a file
    

    To do this parsing in JavaScript you should use jQuery (a small, but powerful library).

    You can include the library directly from Google Code Repository.

    <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
    

    The library is cross-browser and very small. It should be cached in many cases, because some sites use it from Google Code

    $(yourXMLStringOrDocument).find("marker").each(function () {
         var marker=$(this);
    
         var type=marker.find('type').text();
         var title=marker.find('title').text();
         var address=marker.find('address').text();
         var latitude=marker.find('latitude').text();
         var longitude=marker.find('longitude').text();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SNMPv1 uses community strings, which became context-IDs in SNMPv2c. Essentially… May 13, 2026 at 3:53 pm
  • Editorial Team
    Editorial Team added an answer Relative paths are resolved from the location of the file… May 13, 2026 at 3:53 pm
  • Editorial Team
    Editorial Team added an answer Yep. Use std::string internally and then just use const char… May 13, 2026 at 3:53 pm

Related Questions

Let's say I have an empty XML file like so: <root></root> And I want
I have an C# dll project for which I have to store the runtime
I am designing an application where I basically want to load geographical maps that
I am using TortoiseSVN for Windows and want to figure out if I can

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.