PHP XML Tips – Part 8: Do you want to remove child from exist XML? You can use removeChild(). Look at this:
01 |
<?php |
02 |
$file = "books.xml" ; |
03 |
$fp = fopen ( $file , "rb" ) or die ( "cannot open file" ); |
04 |
$str = fread ( $fp , filesize ( $file )); |
05 |
06 |
07 |
|
08 |
$xml = new DOMDocument(); |
09 |
$xml ->formatOutput = true; |
10 |
$xml ->preserveWhiteSpace = false; |
11 |
$xml ->loadXML( $str ) or die ( "Error" ); |
12 |
13 |
// original |
14 |
echo "<xmp>OLD:\n" . $xml ->saveXML() . "</xmp>" ; |
15 |
16 |
// get document element |
17 |
$root = $xml ->documentElement; |
18 |
$fnode = $root ->firstChild; |
19 |
20 |
//get a node |
21 |
$ori = $fnode ->childNodes->item(1); |
22 |
23 |
// remove |
24 |
$fnode ->removeChild( $ori ); |
25 |
26 |
echo "<xmp>NEW:\n" . $xml ->saveXML() . "</xmp>" ; |
27 |
?> |
Books.xml, you can see at this.
Result, like this:
Series this article: PHP – XML: Read from String PHP – XML: Read from a File PHP – XML: Retrieving Node Values PHP – XML: Retrieving Attribute Values PHP – XML: Processing XML PHP – XML: Creating XML Document PHP – XML: Adding XML Nodes PHP – XML: Removing Node PHP – XML: Replacing Node PHP – XML: Filtering XML Nodes with XPath PHP – XML: Filtering XML Nodes by Namespace Tag: xml, node Category: PHP BasicPost : March 23rd 2008 Read: 18,776 |
You produced some decent points there. I looked on the internet for that problem and located most individuals goes along with along together with your internet web site. 866714
Wow! I’m really enjoying the layout of your website. Are you using a custom made template or is this readily available to all individuals? If you do not want to say the name of it out in the public, please e-mail me at: Groshans7489@gmail.com. I’d absolutely love to get my hands on this template! Kudos.
buy xanax online order generic xanax – order xanax off internet
i like what you’ve done
I was suggested this web website by my cousin. Im not certain whether this post is written by him as nobody else know such detailed about my issue. Youre incredible! Thanks! 290555
Hello! I basically would wish to offer a huge thumbs up for that wonderful information youve here during this post. I is going to be returning to your internet site to get far more soon. 694158
Hi, i must say fantastic site you have, i stumbled across it in Yahoo. Does you get much traffic?
Wow! This could be one particular of the most helpful blogs Weve ever arrive across on this subject. Actually Great. Im also an expert in this topic therefore I can understand your hard work. 230792
Hey, are you having issues along with your hosting? I necessary to refresh the page about million times to get the page to load. Just saying 130901
You ought to essentially take into consideration working on growing this blog into a serious authority on this market. You evidently have a grasp handle of the subjects everyone seems to be searching for on this web site anyhow and you possibly can actually even earn a buck or two off of some advertisements. I’d discover following latest subjects and elevating the quantity of write ups you set up and I assure you’d start seeing some superb targeted traffic in the close to future. Just a thought, good luck in whatever you do!
You are my inspiration, I have few web logs and often run out from post :). “‘Tis the most tender part of love, each other to forgive.” by John Sheffield.
Wanted posting. Loads of excellent writing here. I wish I saw it found the site sooner. Congrats! 806964
I gotta favorite this site it seems invaluable invaluable.
Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to more added agreeable from you! By the way, how can we communicate?
dog grooming will be the specialty of my sister, she truly loves grooming every dog in our house 105221
Quite informative and exceptional bodily structure of content material material , now thats user friendly (:. 752053
I’ve said that least 1260101 times. SCK was here
Thanks for another magnificent post. Where else could anyone get that kind of info in such a perfect way of writing? I have a presentation next week, and I am on the look for such info.
Shareyt – Your Social Sharing Hub! Social media marketing simplified http://my-crazylife.com/shareyt improve social media presence for FREE
Thanks, I have just been looking for info about this topic for a long time and yours is the greatest I have found out so far. But, what about the bottom line? Are you certain in regards to the supply?
Some truly nice and utilitarian info on this site, also I think the style has wonderful features.
Thank you, Ive just been searching for information about this topic for a while and yours is the greatest Ive discovered till now. But, what in regards to the conclusion? Are you sure concerning the supply? 434333
Someone essentially help to make seriously articles I would state. This is the first time I frequented your web page and thus far? I amazed with the analysis you made to create this actual post extraordinary. Excellent activity!
Thank you for the auspicious writeup. It in reality was a amusement account it. Look complicated to far delivered agreeable from you! Nevertheless, how can we keep in touch? 946441
The Case For HIIT Cardio – Why You need to Concider it By the way you might want to take a look at this cool website I found 871043
Its exceptional as your other posts : D, regards for posting . 209287
I genuinely enjoy examining on this internet site, it holds excellent posts.
Wow, Thank you because of this blog. Thats all I’m able to say. You certainly have made this site into something thats eye opening and important. You evidently know so much about the topic, youve covered a lot of bases. Great stuff using this part of the internet. Again, thank you with this blog.
Wonderful defeat! I ought to apprentice although you amend your site, how can i subscribe for ones blog website? The consideration taught me to be a appropriate deal. I was bit acquainted with this your transmit offered dazzling transparent concept
I hope you never stop! This is one of the best blogs Ive ever read. Youve got some mad skill here, man. I just hope that you dont lose your style because youre definitely one of the coolest bloggers out there. Please keep it up because the internet needs someone like you spreading the word.
It’s a shame you don’t have a donate button! I’d most certainly donate to this brilliant blog! I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to brand new updates and will talk about this website with my Facebook group. Talk soon!
Hello there, just became aware of your blog through Google, and found that it’s really informative. I’m gonna watch out for brussels. I will be grateful if you continue this in future. Many people will be benefited from your writing. Cheers!
I went over this internet site and I conceive you have a lot of great information, bookmarked (:.
I really enjoy looking through on this website, it contains fantastic articles. “Beware lest in your anxiety to avoid war you obtain a master.” by Demosthenes.
I am really impressed with your writing skills and also with the layout on your weblog. Is this a paid theme or did you modify it yourself? Anyway keep up the excellent quality writing, it is rare to see a great blog like this one nowadays
Attractive section of content. I just stumbled upon your site and in accession capital to assert that I get in fact enjoyed account your blog posts. Any way I’ll be subscribing to your augment and even I achievement you access consistently quickly.