| | |
Update XML Node via PHP...
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 31
Reputation:
Solved Threads: 0
Hi there,
I am trying to update a node in an XML file using PHP.
Here is the XML:
How can I go about searching the XML file for all tags where "id=2" and setting the firstname and lastname nodes to new values?
Any replies would be greatly appreciated!
Mapper
I am trying to update a node in an XML file using PHP.
Here is the XML:
xml Syntax (Toggle Plain Text)
<users> <user> <id>1</id> <firstname>Bob</firstname> <lastname>Marley</lastname> </user> <user> <id>2</id> <firstname>Bruce</firstname> <lastname>Springsteen</lastname> </user> </users>
How can I go about searching the XML file for all tags where "id=2" and setting the firstname and lastname nodes to new values?
Any replies would be greatly appreciated!
Mapper
Last edited by peter_budo; Aug 11th, 2009 at 2:50 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
http://php.net/SimpleXML, You might want to take a look at the xpath stuff.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Apr 2008
Posts: 31
Reputation:
Solved Threads: 0
I have taken a brief look into SimpleXML and have created the following. I just can't get the XML to update:
PHP Syntax (Toggle Plain Text)
$file = 'officedata.xml'; $xml = simplexml_load_file($file); $lastname = $xml->xpath('//user[id="2"]/lastname'); $xml_string=''; while(list( , $node) = each($lastname)) { $xml_string .= $node->asXML(); $xml_string='newlastname'; } echo $xml_string;
![]() |
Similar Threads
- Using a DetailsView Control to Update an XML Datasource... (ASP)
- add a new item to XML file using PHP (PHP)
- How do i store my product information in xml file using php? (MySQL)
- Remove xml node (C#)
- Bullet creation in xml using PHP (PHP)
- Dynamic menu with XML (JavaScript / DHTML / AJAX)
- adding innertext to an xml node (C#)
- Php parser error when xml version is mentioned (PHP)
Other Threads in the PHP Forum
- Previous Thread: Questions about passing variable with URL
- Next Thread: Dynamic Login
Views: 507 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class clean cms code countingeverycharactersfromastring cron curl database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail match menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions simple sms soap source space spam speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






