| | |
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
| Thread Tools | Search this Thread |
.htaccess action ajax apache api array auto beginner binary bounce broken cakephp checkbox class cms code cron curl database date display dynamic echo email error errorlog file files folder form format forms function functions google href htaccess html image include insert integration interactive ip java javascript joomla limit link login loop mail malfunctioning masterthesis menu mlm mod_rewrite multiple mysql nodes oop paypal pdf php popup problem query radio ram random recursion reference regex remote return script search server sessions sms soap source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube






