www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Rss + xsd + php

  1. #1
    Join Date
    Sep 2004
    Location
    Sri Lanka
    Posts
    469

    resolved [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 http://www.webdeveloper.com/forum/sh...142#post961142 , 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

    PHP Code:
    <?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";
    }
    ?>
    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>
    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>
    Thanks and Best Regards
    Last edited by GUIR; 12-18-2008 at 05:21 AM.

  2. #2
    Join Date
    Sep 2004
    Location
    Sri Lanka
    Posts
    469

    resolved Mistake

    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles