Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/252617-create-xml-file/
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/252617-create-xml-file/#findComment-1295087
Share on other sites

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();

?>

Link to comment
https://forums.phpfreaks.com/topic/252617-create-xml-file/#findComment-1295108
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.