ubuntu-user Posted November 26, 2009 Share Posted November 26, 2009 Hello Yesterday I started learning PHPs XML support. I have an XML file I need to update. I've read the file into a variable then run the simplexml_load_string function on it. From there on, I simply extract values as follows: $name = $xml->name; That works for these: <name>test</name> However, I'm stuck on how to extract these attributes: <type first='abc' second='xyz'>standard</type> What I want is the value of "first" and the value of "second". I can get the first value doing this: $type_first = $xml->type->attributes(); However, I can't find a way of getting a specific value. Does anyone know how to extract these? Also how to update them? With this format: <name>test</name> I simply run this to change the value: $xml->name = "New Name"; Thank you. Link to comment https://forums.phpfreaks.com/topic/183046-xml-help-needed-on-extracting-values/ Share on other sites More sharing options...
mrMarcus Posted November 26, 2009 Share Posted November 26, 2009 this might ba of help: XML attributes in PHP Link to comment https://forums.phpfreaks.com/topic/183046-xml-help-needed-on-extracting-values/#findComment-966051 Share on other sites More sharing options...
ubuntu-user Posted November 26, 2009 Author Share Posted November 26, 2009 If anyone else wants to know this, I've worked it out. To get the value of an attribute: $vm_type_arch = $xml->type[first]; To update: $xml->type[first] = "def"; Link to comment https://forums.phpfreaks.com/topic/183046-xml-help-needed-on-extracting-values/#findComment-966054 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.