n2learning Posted December 6, 2011 Share Posted December 6, 2011 I am trying create my xml file in this format: <?xml version="1.0" encoding="UTF-8" ?> - <playlist id="Adobe"> <vid desc="5 minute cardio warm-up" contenu="side jumps, arm curls ..." src="videos/set2_first_5min.flv" thumb="thumbs/set2_first.png" /> <vid desc="5 minutes of no rest workout moves" contenu="Football drills, front kicks ..." src="videos/set2_second_5min.flv" thumb="thumbs/set2_second.png" /> <vid desc="last 5 minutes of Set 1" contenu="MC Hammer ..." src="videos/set2_third_5min.flv" thumb="thumbs/set2_third.png" /> <vid desc="5 minute cardio warm-up" contenu="jumping jacks, presses and squats" src="videos/Set1_first.flv" thumb="thumbs/set1_first.jpg" /> <vid desc="5 minutes of no rest workout moves" contenu="shin kicks ..." src="videos/Set1_mid.flv" thumb="thumbs/set1_mid.jpg" /> <vid desc="last 5 minutes of Set 1" contenu="MC Hammer ..." src="videos/Set1_last.flv" thumb="thumbs/set1_last.jpg" /> </playlist> I'm not having trouble getting and looping through the data from mySQL. I'm getting confused with what's a child element, attribute node, and attribute value. Can someone who has worked with the DOMDocument steer me in the right direction? sample code is the best request Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/252617-create-xml-file/ Share on other sites More sharing options...
kicken Posted December 6, 2011 Share Posted December 6, 2011 I'm getting confused with what's a child element, attribute node, and attribute value. Child element is just an element that is inside of another element. Eg, your <vid> elements which are inside your parent <playlist> element. Attribute node is the combination of an attribute name and value, eg the desc="5" attribute. Attribute value is the value of any attribute. quick xml generation with dom example: <?php $doc = new DOMDocument(); $root = $doc->createElement('playlist'); $root->setAttribute('id', 'Adobe'); //Shortcut to create attributes. $vid = $doc->createElement('vid'); //** Longer way of creating an attribute $attr = $doc->createAttribute('desc'); $attr->nodeValue = 5; $vid->appendChild($attr); //** $root->appendChild($vid); $doc->appendChild($root); echo $doc->SaveXML(); Unless you have a particular need for using the DOM api, if all you want to do is generate and output some xml it is easier to just generate an xml string usually. Quote Link to comment https://forums.phpfreaks.com/topic/252617-create-xml-file/#findComment-1295087 Share on other sites More sharing options...
xyph Posted December 7, 2011 Share Posted December 7, 2011 With SimpleXML <?php $xmlstr = '<?xml version="1.0" encoding="UTF-8" ?><playlist id="Adobe"></playlist>'; $xml = new SimpleXMLElement($xmlstr); $child = $xml->addChild('vid'); $child->addAttribute('desc', '5 minute cardio warm-up'); $child->addAttribute('contenu', 'side jumps, arm curls ...'); //etc header( 'Content-type: application/xml' ); echo $xml->asXML(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/252617-create-xml-file/#findComment-1295108 Share on other sites More sharing options...
n2learning Posted December 7, 2011 Author Share Posted December 7, 2011 Thank you both for your insight. You helped me get this process working! Quote Link to comment https://forums.phpfreaks.com/topic/252617-create-xml-file/#findComment-1295341 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.