Deleting A Node With Known Position In DOM (XML)
I have a a xml with a very basic structure:
<root>
<template name="name0">data0</template>
<template name="name1">data1</template>
<template name="name2">data2</template>
<template name="name3">data3</template>
<template name="name4">data4</template>
<template name="name5">data5</template>
<template name="name6">data6</template>
</root>
I'm trying to remove the 4th node in the file (named name3). The code i'm using for this is:
<?
$i = 3; //Hoping to delete the 4th node.
$doc = new DOMDocument(); $doc->load('file:///var/templates.xml');
$items = $doc->getElementsByTagName('template'); $items2 = $items->item($i);
$itemg = $items2->nodeValue; echo $itemg; //It does return the value of the item i'm trying to delete.
$itemg = $items->removeChild($items2); //Return: "Fatal error: Call to undefined method DOMNodeList::removeChild()"
?>
As said above, the script return Fatal error: Call to undefined method DOMNodeList::removeChild(). I've no idea why it isn't working, and definitely not an idea what the correct code would be.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
XML - Node Manipulation
I was wondering if anyone could point me to any references regarding manipulating XML Child Nodes. I am currently retrieving data from XML in a manner that is useful. However, I am scratching my head when I need to change that information.
Select Node From DOM By ID?
I'm looking for a way to select a <div> by id from an entire xhtml page. I'm not a very experienced coder, but I'm learning... Does php have a fuction for this? it would be like $entire_page = "entire xhtml page fetched from DB which contains <div id='wanted_div'>some content I want</div>"; $my_wanted_div = .... // how do I get the content of 'iwantthisdiv' here?
Children Of Child Node??
Is there any function or way to access the children of a child node using DOM??? I mean if i have the xml structure as: <app> <app_data> <data name='method'><value>sum_dif</value></data> <data name='val1'><value>123</value></data> <data name='val2'><value>456</value></data> <app_data> // child of child node <data name='coool'><value>divo9</value></data> <data name='sands'><value>007</value></data> <data name='make'><value>bond</value></data> </app_data> </app_data> </app> How can I access the data in the child node <app_data>?
Writing A Node To An XML File
I want to write a node or nodes to an existing xml document. I don't need to create a new document, thanks but no thanks. Judging from various posted topics I've seen. It appears the php DOM for XML isn't quite there yet and has a lot of bugs. Not only that it takes a few months before web hosters update versions of php. I tried the pear classes, but they're so poorly documented, there's no example, there's nobody you can contact at Pear for hlep. If you ask for help on forums, you get no reply's so obviously not many ppl are using these classes. I wonder..... if there's a push from say mySQL to stall or slow down PHP's functionality for XML? Any ideas on how to write a node or nodes into an existing XML file..... without a bunch a array manipulation?
Batch File Deleting And Folder Deleting
I have a folder in my web site where I used php to create and copy in files. but now I can't delete them easily. The only way I know how that is possible is through php. I get an error the following ftp error: 550 th: Permission denied I had the chmod() set to 0777 on every file and folder. But I still seem to loss control over the files when I try and do things with them through other means. I think it is because the user I use to access the files via ftp a diffrent user. So I tryed to add a function with chown() for the new files I was posting and uploading. It didn't work on those new files. so it looks like the only thing I can do is use the unlink() function which deletes the files fine. The only problem is now I have something like 100 sub directories all with files in them. I need to figure out a way to batch delete them. I can't find a script that goes through and finds all file contents including all sub directories and unlink those things. I found some that will use a for loop to list out the contents of a folder but it is just files. No sub directories. Any body got any ideas on which functions I should use or know where a script is that I can base mine off of. I am not sure how to approach this since what I tryed with chown and chmod has failed thus far. I currently have no code and am starting from scratch on this batch flushing of my directory.
Can $node->node_value() Return A Null Value?
I am using the following function to access a nodes value from an XML file. It works fine until it discovers a empty tag. I would like to have the option of leaving some tags empty for my script. .. .. .. function foutput_contact ($node_name) { $xml_document = domxml_open_file('xml/contacts.xml'); if ($xml_document) { $nodes= $xml_document->get_elements_by_tagname($node_name); $nodeCount = count($nodes); $node = $nodes[0]; if ($node) { $node = $node->first_child(); return $node->node_value(); } } } The error is returned at the line 'return $node->node_value()' but only when I use an empty node. Can this script be modified to allow empty nodes?
DomDocument: Setting Attributes To A New Node
I'm trying to create a single function to append new nodes to a DOMDocument object: public function addElement( $element, $name, $value = '', $attrs = Null ) { if( !( $created = $this->createElement( $name, $value ) ) ) throw new Exception( 'Could not create a new node ' ); if( !( $child = $element->appendChild( $child ) ) ) throw new Exception( 'Could not append a new node ' ); // Process and attachs the new attributes from array $attrs if any... // if( $attrs ) // foreach( $attrs as $attribute => $value ) // ... } So far, so good. Now I want to set attributes and its values of the recent created node (playing with createAttribute() and setAttribute(), but I can't get the DOMElement from the new child DOMNode. Is it possible without issuing getElementsByTagName() or getElementById() ?? Is another easy way -using DomDocument object- to create a new element (such <table width="50%" border="0">...</table>) which has its attributes and its values ?
After I Load An XML File, Can I Sort It By Node Attribute
After loading an xml file, is it possible to sort it by attribute? For example, I have the following xml file: <xml... <diary> <entry date="2005-01-01">I went to the park</entry> <entry date="2005-01-03">Sold the car today</entry> <entry date="2005-01-02">Went for a stroll</entry> </diary> When I go to load this using PHP, I would use some this similar to this: $xmldoc = domxml_open_file('diary.xml', DOMXML_LOAD_DONT_KEEP_BLANKS); $node = $xmldoc->document_element(); Before I go storming through the xml tree outputing along the way, can I sort it by (in this case) date?
[DOM XML] How To Encode A Node Content (Accentuated Characters)
I'm trying to generate a RSS newsfeed using the DOM XML functions. However I can't find a way to use accentuated characters. I even tried to specify a character encoding set but it doesn't solve the problem. Error I get : XML Parsing Error: not well-formed Location: news.php?action=syndicate&format=rss2 Line Number 1, Column 102:<?xml version="1.0" encoding="ISO-8859-15"?><rss version="2.0"><channel><title>Website title - News ( ---------------------------------------------------------------------------- -----------------------------------------------------------^ The not well-formed character is an accentuated character, as you can see on the following code sample : <?php header ('content-type: text/xml'); echo ('<?xml version="1.0" encoding="ISO-8859-15"?>'); $dom_doc = domxml_new_doc (Ƈ.0'); $rss_el = $dom_doc->create_element ('rss'); $rss_el->set_attribute ('version', ƈ.0'); $rss_el = $dom_doc->append_child ($rss_el); $channel_el = $dom_doc->create_element ('channel'); $channel_el = $rss_el->append_child ($channel_el); $title_el = $dom_doc->create_element ('title'); $title_el = $channel_el->append_child ($title_el); $title_el->set_content ('Website title - News (àéèù)'); echo ($dom_doc->html_dump_mem ()); ?> Removing the accentuated characters from the title generates a well formed XML file. Note that I also tried to encode the characters using the htmlentities function but it didn't change anything.
Position In The DB
A friend and I are trying to make a highscores script for a game. Basically this stores numeric values in a column named `XP`. I want to be able to find out the rank of a user in this column. So I thought why not do something like: $stat_sql = "stat" . $i; $$value = $row[$stat_sql]; $sql = mysql_query( "SELECT * FROM " . $table . " WHERE `loginID` = '$id' ORDER BY `" . $stat_sql . "` DESC" ) or die ( mysql_error() ); while ( $call = mysql_fetch_array( $sql ) ){ $new_var = $value . "_rank"; $$new_var = $call;} But that only outputted "Array". Then I thought even if it didn't output array it would have done 1, because it's only finding one user. I thought the only way to fix this would be to do a general select statement and then loop through all the users till I found that login ID but this script could potentially have thousands of users and I'd rather save bandwidth.
Get Key By Position
If I have an array that looks like this: Array ( [4] => 3 [12] => 2 [20] => 1 [23] => 1 [33] => 1 ); and I want to return the key 4, how would I get that (4 won't always be the key value)?
Anchor Position
Could anyone teach me how to set anchor for a php link? Is the following right? www.test.com?abc=1#anchor_name Or the following? www.test.com#anchor_name?abc=1 Or both are wrong? Besides, could I go to anchor position by PHP command?
Automatic Position?
I have a basic table/database set up to record a persons name, location, the number of miles travelled and their position in a race. At the moment all of these fields have to be entred manually when you wish to update them. Is there a way to automatically assign a position? (i.e. the person who has travelled the most number of miles 1st - least nth?
Displaying A Page At A Specified Position
I have a form about half way down a web page, which posts criteria for the WHERE part of an sql which then returns the results at the bottom of the page. Trouble is when the page reloads it goes to the top of the page again so the results are not visible and the user is sometimes unaware that anything has happened. I could get a message to display at the top to tell user to scroll to bottom but i would prefer the page to display at the start of the records(in a html table).
Modify String In One Position Only
Is it possible to modify a string in one place using an indexing operator and an assignment statement? E.g.: $s = "1234567890"; $s[5] = "d"; // $s is now "12345d7890" According to _PHP Bible_ (2nd ed., p.175), this kind of syntax can work , but is undocumented and, moreover, appears to be discouraged because "almost all PHP string manipulation functions return modified copies of their string arguments rather than making direct changes, which seems to indicate that this is the style that the PHP designers prefer." I did a google search (both www and USENET) and found nothing on this.
Position Of String Occurence
I have a string like "lalala: djkahsd : dajkdassd : adasd :" Is there a function to find the position of the "I"th occurence of a character/string? Like lets say I want to find out the position of the second colon. How do I go about that?? I can only find functions that return the position of the first or last occurence, but not a variable occurence ::sniffles::
White Space Position
how do i find if there is white space in a string eg. "hello how are you?" also how do i return the position of that white space?
How To Position The Page To The Center?
I'm trying to wrap a certain website and then make it load to the center position automatically when the page is loaded. I tried anchor but it doesn't seem to work. And the main menu of that website seems to align itself according to the width specified - but I need to the iframe to be 300 pixels. <div align="center"><iframe src="www.phpfreaks.com#Summary" width="300"></iframe></div> Or how to make them position to where their last scroll position is the next time when they click the links inside the iframe?
Arrays: Inserting At Current Position
I've trying to insert a new element in a numeric array for the past hour with no luck. I came close but didn't succeed. I thought of slicing the array into two others pushing the new element at the bottom of the first slice and merging with the second. The problem is though that the second slice's keys are left intact so the new element of the first slice gets overwritten after merging since it has the same key as the second slice's first element. I tried array_unshift to reindex the second slice by adding something to the top of it but what I should really do is reindex without adding because that something would also overwrite the new element. So, is there a way doing an insert (= pushing down once all elements at current position and getting in the place of the current element) in an array?
Counting Position Of Character In String
I am trying to calculate the postition(s) of a certain character in a string. e.g (a binary string) ??', I want to calculate the Ƈ' in the whole string and returning the charatersplace like Ɖ|4|7', meaning that the 1 appears in the 3rd,4th and 7th position in the string.
Roll To Web Page Vertical Position
I have a php web page which lets users to select choices from combo box and submit the page to update the item description. However, when I have many items on the same page, the row position reset to the beginning of the page. So this makes trouble to the users that he has to find again the product item row position to see the item desctiption. Could anyone tell me how to automatically roll the web page to the vertical positon which is same as previous page?
Position In Array In A Foreach Loop
I have a script that checks an array for names and if that person's name is there it will e-mail them a particular variable. Here is the setup: an array such as $names = array( $name1, $name2, $name3, $name4 ); etc. Then a foreach loop foreach ( $names as $person ){ if ( $key == 1 ){ $color = blue;}} However I need something that will get the position in the array of the variable that the foreach loop is dealing with. I tried array_search but that gets screwed up if someone is in the array more than once, it will then only stop at the first time they are in the away.
Getting The Position Of X Occurance Of A Char In A String
I know that strpos gets the position of the first occurance of N character in a string and that strrpos gets the position of the last occurance of N character in a string. But say I have a string that has 5 :'s in it. a:b:d:c:e:f How would i get the position of the Xth occurance, say, the 3rd. I've been looking all around and havent really found anything, maybe I havent researched it extensively enough.
Getting The Current Position Of A Cursor In A Text Box
Say a user has their cursor in a text box and they click a button and want to add some information in, how would I get the current position of the cursor in the textbox to add that information in to that specific place?
Explicit Numeric Keys Vs Item Position
Say if I have a mixed array: $array = array("item1", "2"=>"item2", "5", "item4key"=>"item4") Is it possible while looping through the array (foreach ($array as $key=>$val)) to check if an item has an explicit key specified instead of its automatically assigned position key?
Call Variable Based On Array Position
wondered if it's possible to call a previously set variable(s) by using an array position. For example if I have variables myvar01, myvar02, myvar03 can I somehow call these in a loop, interchanging the numbers? Here is a simplified version of my code:
Deleting
how could i delete everything from a table in a mysql db except for the 10 latest things ?
Deleting All Files
Is it possible to delete all files in a folder using unlink() or something similar?
Deleting The Saved Db The One Before?
I made a script that backups the database as sql file in the server. I mean script writes it into the harddrive, but everytime when i execute the script the harddrive loss another 3 mb. How can i modify the script to delete the one before when i execute it to write the new one?
Need Help With Deleting Records
I'm trying to add a link on the display of a record to delete that record. The main part of the record is stored in pw_event, then there are several rating fields for that record stored in pw_rate, and there is also several records for the first record stored in pw_whois. I need to have a link that will deleted everything for that record in all three tables. Here is my display script: PHP Code:
Deleting Last Comma
The code below displays pet names like so: Fido, Bowser, Kittycat, Spot, and I want to delete only the last comma. I tried 'substr' and 'rtrim' and both of those delete the space and comma between each name, not just the last name as I'd like, so I end up with: Fido,Bowser,Kittycat,Spot, How would I delete only the last comma, so that it is this instead? Fido, Bowser, Kittycat, Spot Even with trim and substr, I end up with:
Deleting A Session
I want to be able to delete a session so that the next time there's a call to session_start, it creates a new session ID. I don't want to destroy the session variables specifically (though this will be a side-effect of what I'm doing) so I know that session_destroy isn't what I want to do. I presume I should just delete the session cookie manually. Is there a neater way? And if not, how do I do this?
Deleting A Director
I'm using this code trying to make ato delete a file or folder under w2k, apache. $direct=split("repadmin.php",$PATH_TRANSLATED); $file=$direct[0].$filedeleted; $filesys = eregi_replace("/","",$file); $delete = @chmod ($filesys, 0775); unlink("$delete"); header("Location:repadmin.php"); exit; but return this warning: Warning: unlink(1) [function.unlink]: No such file or directory in c:program filesapache groupapachehtdocsguonline epositorio epadmin.php on line 94 I checked the whole path and looks good.
Deleting Files
The below should delete files from a dir older than a week. I set the $dtime to 0 to test the script but it deletes nothing. What is wrong? Code:
Deleting Files
I'm using different files to store some arrays to make administration of a very small job-logger very easy. I currently read the file, remove the element to be deleted, delete the whole file, and write the file again without that element. Is there a way to remove a single element out of that file without deleting the whole file?
Deleting A Line
how do i delete from a text file 1 of the following lines jon|scott adam|smith <--delete paul|clark say i would like to delete the middle line of this txt, in member.txt what php code or logic would help me accomplish this? Also i am clicking on a hyperlink that is keeping count of the entries i have made. e.g php?record_id =1 php?record_id =2
Deleting A Record.
One last (hopefullly) problem I can't seem to get around for this program...why isn't this deleting the row i want? It does nothing. Now error messages either. HELP! $link = mysql_connect("localhost"); if(! $link) die("Could not connect to MySQL"); $database = "PC_Store"; mysql_select_db($database) or die ("could not open $database: ".mysql_error() ); $result = mysql_query("DELETE FROM inventorydata VALUES('$ProductID')"); The $ProductID variable is brought in from a menu choice on a diffrent page, it is also the primary of the table...so it should delete the whole row right?
Deleting Records
I've been trying to delete records since a week and i'm not able to do it. Before with this script, i was doing so many things at a time and i was confused.But, now, i just displaying the records from a table N trying to delete them.Would somebody pls guide me. I just wanna set the delete flag(i.e, i want to set the RBS_DELETE column to Y or something) when i check a check box to delete it. I've some 5 records displaying on my form and i want to check 3 of them and when i check them and hit submit, i want the RBS_DELETE column to have some value. PHP Code:
Deleting A Row From A Database
I can't fiqure out why my delete function isn't working. I have a listing of rows in my database with an option to delete an individual row at the end: Code:
Deleting A Message
I want a button to delete each message in you inbox wen clicked. im using this that doesn't work, because i coded it Code:
Cookie Not Deleting
login.php: setcookie('id', $userinfo['id'], time()+60*60*24*31*3 , '/'); logout.php: setcookie('id', '', time()-60*60*24*2); Any idea why it is not deleting my cookie?
Deleting Posts
How can I delete my previous post? It's showing up in Google when I search for the url referenced in my previous post (if I put the name here, it will show this post, too). If I can't delete it, can I make it so that Google can't pick it up?
Deleting Files
I'm trying to modify this script to remove files that end with %enlarged.jpg or %enlarged.gif or %enlarged.png, can someone help with the if statement, I've tried several things, of which, nothing is working: Code:
Deleting Folder
is there anyway of deleteing a folder and deleting all of its contents with it? i know that with rm_dir needs to folder to be emptied
|