/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Rss + xsd + php

Hi,

I am in need of validating a RSS file which is generated by a program and so I developed a XSD schema and tried to validate a RSS file with that using DOM.

It didn’t work not sure whether my schema is not valid, I have posted in XML section [URL=”http://www.webdeveloper.com/forum/showthread.php?p=961142#post961142″]http://www.webdeveloper.com/forum/showthread.php?p=961142#post961142[/URL] , and my question is, is my approach to validate RSS via PHP is correct.

Also are there any alternatives to validate a RSS feed.

PHP File

[code=php]<?php
$xdoc = new DomDocument;
$xmlfile = ‘xml/rss.xml’;
$xmlschema = ‘xml/rss.xsd’;
//Load the xml document in the DOMDocument object
$xdoc->Load($xmlfile);
//Validate the XML file against the schema
if ($xdoc->schemaValidate($xmlschema)) {
print “$xmlfile is valid.n”;
} else {
print “$xmlfile is invalid.n”;
}
?>[/code]

Schema File

[CODE]
<?xml version=”1.0″?>
<xsd:schema xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>
<xsd:element name=”rss” maxOccurs=”1″ minOccurs=”1″>
<xsd:complexType>
<xsd:attribute name=”version” type=”xsd:string” default=”2.0″ />
<xsd:element name=”channel” maxOccurs=”1″ minOccurs=”1″>
<xsd:complexType>
<xsd:element name=”title” minOccurs=”1″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”link” minOccurs=”1″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”14″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”description” minOccurs=”1″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”image” minOccurs=”0″ maxOccurs=”1″>
<xsd:complexType>
<xsd:element name=”title” minOccurs=”1″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”link” minOccurs=”1″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”14″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”url” minOccurs=”1″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”14″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”description” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”width” minOccurs=”0″ maxOccurs=”1″ default=”88″>
<xsd:simpleType>
<xsd:restriction base=”xs:integer”>
<xsd:maxExclusive value=”144″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”height” minOccurs=”0″ maxOccurs=”1″ default=”31″>
<xsd:simpleType>
<xsd:restriction base=”xs:integer”>
<xsd:maxExclusive value=”400″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:complexType>
</xsd:element>
<xsd:element name=”category” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”copyright” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”docs” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”generator” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”language” minOccurs=”0″ maxOccurs=”1″ default=”en-us”>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”5″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”lastBuildDate” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”10″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”managingEditor” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”5″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”pubDate” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”10″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”skipDays” minOccurs=”0″ maxOccurs=”1″>
<xsd:complexType>
<xsd:element name=”day” minOccurs=”1″ maxOccurs=”6″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:complexType>
</xsd:element>
<xsd:element name=”skipHours” minOccurs=”0″ maxOccurs=”1″>
<xsd:complexType>
<xsd:element name=”hour” minOccurs=”1″ maxOccurs=”23″>
<xsd:simpleType>
<xsd:restriction base=”xsd:integer”>
<xsd:maxExclusive value=”23″/>
<xsd:minExclusive value=”0″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:complexType>
</xsd:element>
<xsd:element name=”ttl” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xsd:integer”>
<xsd:minExclusive value=”1″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”webMaster” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”5″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<!– Item –>
<xsd:element name=”item” maxOccurs=”unbounded” minOccurs=”1″>
<xsd:complexType>

<xsd:element name=”title” minOccurs=”1″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”link” minOccurs=”1″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”14″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”description” minOccurs=”1″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”category” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name=”comments” minOccurs=”0″ maxOccurs=”1″>
<xsd:simpleType>
<xsd:restriction base=”xs:string”>
<xsd:length value=”2″/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:complexType>
</xsd:element>
</xsd:complexType>
</xsd:element>
</xsd:complexType>
</xsd:element>
</xsd:schema>
[/CODE]

RSS File

[CODE]
<?xml version=”1.0″ encoding=”ISO-8859-1″ ?>
<rss version=”2.0″><channel>
<title>Schools Home Page</title>
<link>http://www.schools.com</link>
<description>Free web </description>
<item>
<title>RSS </title>
<link>http://www.schools.com/rss</link>
<description>New RSS tutorial</description>
</item>
<item>
<title>XML Tutorial</title>
<link>http://www.schools.com/xml</link>
<description>New XML tutorial on School</description>
</item>
</channel></rss>
[/CODE]

Thanks and Best Regards

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@GUIRauthorDec 18.2008 — The Schema in above is invalid, those who are interested in a proper Schema for RSS 2.0 please go to section XML with the link I mentioned in earlier post.
×

Success!

Help @GUIR spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...