HardCoreMore Posted October 3, 2008 Share Posted October 3, 2008 Hi, i have problem with controlling XML file so please send me link if you know the post that my solve my problem. This is the structure of xml that i need. <content> <user id="12"> <pic>some value</pic> <pic>some value</pic> <pic>some value</pic> </user> <user id="28"> <pic>some value</pic> <pic>some value</pic> <pic>some value</pic> <pic>some value</pic> </user> <user id="54"> <pic>some value</pic> <pic>some value</pic> </user> </content> So how can i open this xml and find all children of user tag where id in user tag has value of 54 for example so that i know how many pic tags are there cauz value inside pic is going to be picture name for certain user and i want to limit number of pic tags so that user can only upload 20 pictures. How can i add new user tag to this xml? How can i add and delete new pic tag inside user tag where id is 28 for example. I searched the php manual and i found DomDocument functions for editing xml but they are so unclear to me. I really don't know how to use them. Only i know by far is to open xml with domxml_open_file() I hope that you understand what i want to achieve. Any help is welcome. Link to comment https://forums.phpfreaks.com/topic/126880-php-and-xml/ Share on other sites More sharing options...
blundell Posted October 3, 2008 Share Posted October 3, 2008 Most of what you asked is relatively easy : http://www.kirupa.com/web/xml_php_parse_intermediate.htm Link to comment https://forums.phpfreaks.com/topic/126880-php-and-xml/#findComment-656253 Share on other sites More sharing options...
HardCoreMore Posted October 3, 2008 Author Share Posted October 3, 2008 Thanks man i found great tutorial about php and xml on phpfreaks. They saved me so much trouble. Link to comment https://forums.phpfreaks.com/topic/126880-php-and-xml/#findComment-656292 Share on other sites More sharing options...
HardCoreMore Posted October 8, 2008 Author Share Posted October 8, 2008 I was reading some tutorials on how to parse and edit xml. I found that best solution is to use simple xml and dom in combination but i still have one problem. I know how to add an element but i don't know how to add and attribute at the same time when i am adding new element. So i am using this code to add a new element. $book = simplexml_load_file('book.xml'); $daj = $book->user[0]; $dom = dom_import_simplexml($daj); $dom->appendChild(new DOMElement("pic", "New Value")); So when i add this new element to the xml how can i add and attribute to that element with some value. Link to comment https://forums.phpfreaks.com/topic/126880-php-and-xml/#findComment-659867 Share on other sites More sharing options...
HardCoreMore Posted October 8, 2008 Author Share Posted October 8, 2008 If i change code to this $book = simplexml_load_file('book.xml'); $daj = $book->user[0]; $dom = dom_import_simplexml($daj); $dom->appendChild(new DOMElement("pic", "New Value",[color=red]"attValue"[/color])); He makes node and makes attribute with value attValue but i can't choose the name of the attribute? Instead he makes automatically name "xmlns". Why is that happening? Link to comment https://forums.phpfreaks.com/topic/126880-php-and-xml/#findComment-659879 Share on other sites More sharing options...
HardCoreMore Posted October 8, 2008 Author Share Posted October 8, 2008 I am sorry the last post has one mistake. I didn't want to write "attValue". I wanted to make "attValue" to be red but it seams their parser didn't do it. Link to comment https://forums.phpfreaks.com/topic/126880-php-and-xml/#findComment-659882 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.