Jaxel
Well-known member
Right now I am using DOMDocument (as does XenForo) to create XML. Is there a better way?
Just to get this VERY SIMPLE XML:
It takes this amazingly large amount of confusing code...
There has to be a better way...
Just to get this VERY SIMPLE XML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url>
<loc>http://www.8wayrun.com/media/necxi-sc4-ft10-50-mm-mick-vs-dina.1804/</loc>
<video:video>
<video:thumbnail_loc>http://www.8wayrun.com/data/media/1804.jpg</video:thumbnail_loc>
<video:title><![CDATA[NECXI SC4 - FT10 $50 MM - Mick VS Dina]]></video:title>
<video:description><![CDATA[Streaming video brought to you by Jaxel of http://www.8wayrun.com. This was part of the Soulcalibur IV Money Matches at NEC XI in Philadelphia, PA. Stream can always be found by following Jaxel on twitter: http://twitter.com/JasonAxelrod
Want Jaxel to stream one of your tournaments? Contact him on SRK or 8WR to learn how to hire him. Sponsorship opportunities also available.]]></video:description>
<video:player_loc><![CDATA[http://www.youtube.com/v/jat8T6x2NxU?autoplay=1&hd=1&fs=1]]></video:player_loc>
<video:duration>3046</video:duration>
<video:view_count>26</video:view_count>
<video:publication_date>2010-12-09T22:09:51+00:00</video:publication_date>
<video:tag>sophitia</video:tag>
<video:tag>xianghua</video:tag>
<video:category><![CDATA[BigE Gaming / GVN]]></video:category>
<video:uploader info="http://www.8wayrun.com/members/jaxel.1/">Jaxel</video:uploader>
</video:video>
</url>
</urlset>
It takes this amazingly large amount of confusing code...
Code:
<?php
class EWRmedio_Model_Sitemaps extends XenForo_Model
{
public function getMRSSbyMedia($media)
{
$document = new DOMDocument('1.0', 'utf-8');
$document->formatOutput = true;
$set_node = $document->createElement('urlset');
$xns_node = $document->createAttribute('xmlns');
$xns_node->appendChild($document->createTextNode('http://www.sitemaps.org/schemas/sitemap/0.9'));
$vns_node = $document->createAttribute('xmlns:video');
$vns_node->appendChild($document->createTextNode('http://www.google.com/schemas/sitemap-video/1.1'));
$set_node->appendChild($xns_node);
$set_node->appendChild($vns_node);
$url_node = $document->createElement('url');
$url_node->appendChild($document->createElement('loc', XenForo_Link::buildPublicLink('full:media', $media)));
$vid_node = $document->createElement('video:video');
$tit_node = $document->createElement('video:title');
$tit_node->appendChild($document->createCDATASection($media['media_title']));
$des_node = $document->createElement('video:description');
$des_node->appendChild($document->createCDATASection(XenForo_Helper_String::bbCodeStrip($media['media_description'])));
$mov_node = $document->createElement('video:player_loc');
$mov_node->appendChild($document->createCDATASection($media['service_movie']));
$cat_node = $document->createElement('video:category');
$cat_node->appendChild($document->createCDATASection($media['category_name']));
$tags = explode(',', $media['media_keywords']);
$vid_node->appendChild($document->createElement('video:thumbnail_loc', XenForo_Application::get('options')->boardUrl.'/data/media/'.$media['media_id'].'.jpg'));
$vid_node->appendChild($tit_node);
$vid_node->appendChild($des_node);
$vid_node->appendChild($mov_node);
$vid_node->appendChild($document->createElement('video:duration', $media['media_duration']));
$vid_node->appendChild($document->createElement('video:view_count', $media['media_views']));
$vid_node->appendChild($document->createElement('video:publication_date', date("c", $media['media_date'])));
foreach ($tags AS $tag) { $vid_node->appendChild($document->createElement('video:tag', trim($tag))); }
$vid_node->appendChild($cat_node);
$usr_node = $document->createElement('video:uploader', $media['username']);
$inf_node = $document->createAttribute('info');
$inf_node->appendChild($document->createTextNode(XenForo_Link::buildPublicLink('full:members', $media)));
$usr_node->appendChild($inf_node);
$vid_node->appendChild($usr_node);
$url_node->appendChild($vid_node);
$set_node->appendChild($url_node);
$document->appendChild($set_node);
return $document;
}
}
There has to be a better way...