473,785 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete element in xml file by using php

Hi,
I have a application which has a xml file reading and wrting. I want
to remove some element in xml file by using php.
<?xml version="1.0" encoding="UTF-8"?>
<element1>
<subelement1>aa </subelement1>
<subelement2>aa </subelement2>
</element1>
How to remove "<subelement1>a a</subelement1>" that elements and save
back to same or other xml file.
Aug 23 '08 #1
2 10698
Samudaya wrote:
Hi,
I have a application which has a xml file reading and wrting. I want
to remove some element in xml file by using php.
<?xml version="1.0" encoding="UTF-8"?>
<element1>
<subelement1>aa </subelement1>
<subelement2>aa </subelement2>
</element1>
How to remove "<subelement1>a a</subelement1>" that elements and save
back to same or other xml file.
Check out the PHP manual:

SimpleXML: <URL:http://www.php.net/manual/en/book.simplexml. php>
DOM (PHP 5): <URL:http://www.php.net/manual/en/intro.dom.php>

If you're stuck with PHP 4:
<URL:http://www.php.net/manual/en/ref.domxml.php>

--
Curtis (http://dyersweb.com/)
Aug 23 '08 #2
<?xml version="1.0" encoding="UTF-8"?>
<element1>
* * <subelement1>aa </subelement1>
* * <subelement2>aa </subelement2>
</element1>

How to remove *"<subelement1> aa</subelement1>" that elements and save
back to same or other xml file.
first of all, i wouldnt call each element element1 and element2 etc
just element. You can store the meta data such as a number as an
attribute instead. I'd do something like this (off the top of my head
and untested)...
$xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<element num="1">
<subelement1>aa </subelement1>
<subelement2>aa </subelement2>
</element>
</xml>
XML;

$dom = new DOMDocument();
$dom->loadXML($xml );

$xpath = new DomXpath($dom);

$result = $xpath->query("//element");
$result->parentNode->removeChild($r esult->item(0));

$dom->saveXML();

Aug 23 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
331
by: Michal Januszczyk | last post by:
Hello. Sometimes I encounter the following problem: foreach( element of some collection) { delete this element; } of course, the runtime would not allow to modify
8
2531
by: Richard Arthur | last post by:
This is a weird problem. 1) I use MediaDet to save a bitmap in a temporary file. 2) I create a bitmap using that temporary file's name. 3) I use the bitmap. 4) I want to destroy the file when the process exits, but I am having trouble I have written a Finalizer on the object that actually generates the bitmaps, as well as implementing IDisposable. The finalizer gets called, I then call Dispose on each of the bitmaps it the object has...
2
1772
by: Pujo Aji | last post by:
Hello, I would like to create program which delete files using * symbol. I tried to use this code but it is not working: File.Delete(@"d:\example.*");//filename example, directory everthing, it stop here : file not found Any idea? Thanks
3
2932
by: News | last post by:
Is it possible to delete a file by copying it to the "bit bucket" or "null device"? Back in my youth when I live in VMS-land you could delete a file by copying it to NL: ========== I have written a windows service as part of an interface between two different systems. The first system will write output into a file in a
6
2876
by: ashasprabhu | last post by:
hi, how to delete a file using asp.net with vb.net
5
3829
by: Rohit111111 | last post by:
Hello All, I new to ASP and i am using VBScript, I want to delete a file which is located on the remote machine hbow can i delete that file.plz help its urgent
1
3835
by: Zuhaib Hyder | last post by:
how to delete client file using c# or javascript ? file delete prmissions are already given?
1
14173
by: Softnile | last post by:
Hi I tried to use the following code to delete file in javascript, BUT this code gives an error smthing like.. "Automation cant create object" Can anyone give solution to this problem OR can i use any optional coding for this problem. I used :Following Code Plz help .Its urgent....
1
2047
by: fishjelly | last post by:
How to edit and delete the data stored in xml file using C# and visual studio 2005 through user input? For example: for this xml document... <MenuRoot> <Books> <book> <title> ABC </title> <author>DEF</author>
2
1198
by: hemapooja | last post by:
Hi, I am using vb.Net web application. I am getting the error of system.io. ioexception. The process can't access the file because it is being usrd by another process. when file is opened or not the file should be deleted from the path Need the solution for this issue.
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.