Jump to content

Error for Simple XML Element


Graxeon

Recommended Posts

Thanks for the links...I'm not much of a PHP expert so I may have a hard time with it xD

 

I am pulling the contents of sf:media from a file.

 

If anyone else can give me an exact answer...I'd be very thankful :). But...I hope those links will do :P

 

Did you create the feed, or was the feed created from another source?

Link to comment
Share on other sites

I created it...why?

 

I do not think it is valid XML Syntax, hence why you are getting the error. I would read up more on proper XML syntax.

 

:media, I think should be an attribute:

 

<sf type="media">Here </sf>

 

Or look into namespaces as suggested above.

Link to comment
Share on other sites

Does it matter what it's called? Because even though it is invalid it can still be read by other scripts if those scripts use the same tag.

 

Umm...as for the name space thing...the 2 pages you gave me were confusing...

 

Example...what is this? lol:

 

::=  ('"' [^"]* '"') | ("'" [^']* "'")

Link to comment
Share on other sites

Ok...here's the RSS file and also a new code that should work but doesn't (it's a little different from the one that I provided earlier) :

 

<rss version="2.0">

<sf:configuration>
<sf:siteurl>http://domain.com/</sf:siteurl>
<sf:sitename>Domain</sf:sitename>
<sf:font>IMPACT</sf:font>
<sf:fontsize>20</sf:fontsize>
<sf:logo/>
<sf:logoalpha>50</sf:logoalpha>
<sf:share>true</sf:share>
<sf:upload>true</sf:upload>
<sf:borderstyle>0x000000</sf:borderstyle>
<sf:backgroundstyle>null</sf:backgroundstyle>
<sf:textcolor>0x000000</sf:textcolor>
<sf:objectcolor>0x000000</sf:objectcolor>
<sf:buttoncolor>0x00cccc</sf:buttoncolor>
<sf:backgroundcolor>0x000000</sf:backgroundcolor>
<sf:analytics_key>UA-187186-1</sf:analytics_key>
<sf:video_analytics_key>123456</sf:video_analytics_key>
</sf:configuration>
<ad_sys_spec aggregate_views_per_user="10" view_frequency="3"/>

<ad_spec id="0" desc="empty" startdate="01012008" enddate="12312020" views_per_user="1000" overlay_provider="OVERLAY_PROVIDER" overlay_channel_id="OVERLAY_CHANNEL_ID">

<selection>

<channel>

<title>
Welcome Video
</title>
\r
<description/>
\r
<link>http://domain.com/</link>
\r
−
<image>
<url>http://domain.com/footer.jpg/url>
<link>http://domain.com</link>
<title>Welcome</title>
<height>41</height>
<width>210</width>
</image>
<language>en-us</language>
<pubdate>Sat, 07 Feb 2009 21:37:56 GMT</pubdate>
\r

<playlist sort="1" orderby="1">

<item>
\r

<title>
Welcome Video
</title>
\r
<author>Admin</author>
\r
<pubDate>Tue, 14 Oct 2008 15:37:00 GMT</pubDate>
\r

<link>
http://domain.com/welcome.html
</link>
\r

<description>
Welcome Video
</description>
\r

<media:text type="html">
Welcome Video<br /><br /><img src="http://domain.com/image.jpg" border="0" />
</media:text>
\r
<media:player url="http://domain.com/welcome.html"/>
\r
<media:content url="http://domain.com/player.swf?=" type="application/x-shockwave-flash" medium="video" height="352" width="428" duration="220"/>
\r

<media:title>
Welcome Video
</media:title>
\r
<media:keywords/>
\r

<media:description>
Welcome Video
</media:description>
\r
<media:thumbnail url="http://domain.com/thumb.jpg" height="150" width="200"/>
\r
<guid isPermaLink="true" url="http://domain.com/" guid="welcome.html"/>
\r
<sf:kudos curmonth="0" month="0" total="0"/>

<sf:avatar>
http://domain.com/image.jpg
</sf:avatar>
\r

<sf:mediapath>
http://domain.com/welcome.flv
</sf:mediapath>
\r
<sf:mediaid>954392</sf:mediaid>
\r
<sf:views>3649</sf:views>
\r
<sf:dateadded_verbose>October 14, 2008</sf:dateadded_verbose>
</item>
</playlist>
\r
</channel>
</selection>
</ad_spec>
</rss>

 

And this is the code that should be able to call the contents within "sf:media" ...but I can't get it to work:

 

**Note: http://domain.com/feed-~input~ is the RSS code above--^

 

<?php
$allowed_url = array("welcome", //Welcome video
"blankspothere");

$passed_url = $_GET['url'];

foreach ($allowed_url as $allowed) {
     if(stristr($allowed, $passed_url) !== false) {
  $url='http://domain.com/feed-'.$_GET['url'];
  $sxml = simplexml_load_file($url);

  list($node) = $sxml->xpath('/rss/ad_spec/selection/channel/playlist/item/sf:mediapath');
  header('Location: '.$node['url']);
           exit;
     }
}

   header("Location: http://www.google.com/");
?>

 

 

Does this information help?

Link to comment
Share on other sites

OK, you should have looked at NAMESPACES better, because sf IS a namespace.

 

Take a look at http://www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/ for more info about namespaces.

 

You can also use getDocNamespaces() or getNamespaces(), and here is more info on it:

 

http://www.w3schools.com/php/func_simplexml_getdocnamespaces.asp

http://www.w3schools.com/php/func_simplexml_getnamespaces.asp

 

Also see the php manual (but there are no examples).

 

As soon as you declare the namespaces the corrent way, you will be able to start parsing those elements.

Link to comment
Share on other sites

I'm a little lost...I got this from one of the links you gave me:

 

<?php

$feed = simplexml_load_file('http://www.sitepoint.com/recent.rdf');
foreach ($feed->item as $item) {
  $ns_dc = $item->children('http://purl.org/dc/elements/1.1/');
  echo $ns_dc->date;
}

?>

 

$feed would be replaced by my feed. Then it's saying to take each of the items within the feed and extract the date after the "dc" namespace. However...what does "http://purl.org/dc/elements/1.1/" have to do with anything?

 

That script itself works perfectly...but I don't understand how I should alter it and implement that idea into my script:

 

<?php
$allowed_url = array("welcome", //Welcome video
"blankspothere");

$passed_url = $_GET['url'];

foreach ($allowed_url as $allowed) {
     if(stristr($allowed, $passed_url) !== false) {
  $url='http://domain.com/feed-'.$_GET['url'];
  $sxml = simplexml_load_file($url);

  list($node) = $sxml->xpath('/rss/ad_spec/selection/channel/playlist/item/sf:mediapath');
  header('Location: '.$node['url']);
           exit;
     }
}

   header("Location: http://www.google.com/");
?>

Link to comment
Share on other sites

To get at your sf namespace elements, you need to replace dc with sf.

 

http://purl.org/dc/elements/1.1/ is the description of the dc namespace, but looking at your xml, you might need to get at the sf namespace through the getNamespace function. This URI is kinda like a description of what is inside the sf namespace, and what form of data is there.

 

BTW, the XML that you shared does not look valid. Where did you get it? Maybe if you can share the source, and hook me up with the URI, I'll try to parse it for you.

Link to comment
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.