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 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

Related Questions

have an xml file like this. <?xml version =1.0 encoding =utf-8?> <menu> <menuNode title=Register
i have xml file that looks like this: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE pointList SYSTEM
I ran into the following problem. I have an xml-file like this: <Source Name
I want to modify some data on XML file residing on server side by
I want to read in an XML file and modify an element then save
I am using the following code to modify the XML file that can be
i have that xml file : <?xml version=1.0 encoding=utf-8?> <reminders> <reminder> <Title>Alarm1</Title> <Description>Desc1</Description> <Time>03/07/2012
I have an XML file I'm trying to modify and want to add a
I have a xml file which I modify with the following code: XmlDocument xlDoc
I want to modify an existing XML-File. I used a DataSet to load the

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.