web

XML DTD and XML Schema, RSS FEED

XML DTD

XML DTD एक Formal Specification है, जो XML Document के Structure और Legal Element और Attribute को Define करता है। यह XML Document की Integrity को Validate करने के लिए एक Blueprint के रूप में कार्य करता है, यह सुनिश्चित करते हुए कि वे Rule के Predefined Set का पालन करते हैं।

Example:


<!– Sample XML Document –>
<!DOCTYPE bookstore [
<!ELEMENT bookstore (book+)>
<!ELEMENT book (title, author, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT price (#PCDATA)>
]>
<bookstore>
<book>
<title>Introduction to Web Technologies</title>
<author>John Doe</author>
<price>29.99</price>
</book>
<!– Additional books go here –>
</bookstore>

इस Example में, DTD एक Bookstore XML Document Structure को Define करता है। यह Specify करता है, कि एक Bookstore में एक या अधिक Book होनी चाहिए| और प्रत्येक Book का एक Titile, एक Author और एक Price होनी चाहिए। #PCDATA Parse किए गए Character Data को Indicate करता है, जो Specific Element के भीतर Text Content की Permission देता है।

Advantages of XML DTD

  • Simplicity: DTD Simple और समझने में आसान हैं, जो उन्हें Low Complex Document Structure के लिए Suitable बनाता है।
  • Compatibility: विभिन्न XML Application के साथ Compatibility सुनिश्चित करते हुए DTD को व्यापक रूप से बनाया गया है।

XML Schema

XML Schema, जिसे XSD (XML Schema Definition) के रूप में भी जाना जाता है, DTD का एक XML-Based Alternative है। यह XML Document Structure को Describe करने के लिए अधिक Pwerful और Flexible Way Provide करता है। XML Schema XML में ही लिखी जाती है, जो इसे DTD की तुलना में अधिक Expressive और Extensible बनाती है।

Example:


<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”>
<xs:element name=”bookstore”>
<xs:complexType>
<xs:sequence>
<xs:element name=”book” type=”xs:complexType”>
<xs:sequence>
<xs:element name=”title” type=”xs:string”/>
<xs:element name=”author” type=”xs:string”/>
<xs:element name=”price” type=”xs:decimal”/>
</xs:sequence>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

इस Example में, हम एक Complex Type के साथ एक Bookstore Element को Define करते हैं| यह Define करते हुए कि इसमें Book Element का एक Order Included है। प्रत्येक Book Element में Specific Data Type के साथ Title, Author और Price Element का एक Order होता है।

Introduction of RSS FEED

RSS (Really Simple Syndication) एक Web Feed Format है, जो User को Standardized Way से Online Content के Update को Access करने की Permission देता है। इसका use Blog, News Website और अन्य Online Publication की Subscription लेने के लिए व्यापक रूप से किया जाता है।

RSS Basic

RSS Feeds, XML-Based File हैं| जिनमें किसी Website पर Latest Update या Entries के बारे में Information होती है। उनमें आमतौर पर Title, Summaries और Full Content के Link Included होते हैं। RSS Users को किसी Website की Subscription लेने और New Content Publish होने पर Information Receive करने की Permission देता है।

Creation of RSS Feed

RSS Feeds बनाने के लिए RSS Specification के अनुसार XML Data की Structring करने की आवश्यकता है।

Example:


<?xml version=”1.0″ encoding=”UTF-8″ ?>
<rss version=”2.0″>
<channel>
<title>Example RSS Feed</title>
<link>http://www.example.com</link>
<description>Latest updates from Example Website</description>

<item>
<title>First Post</title>
<link>http://www.example.com/posts/first-post</link>
<description>This is the first post on Example Website.</description>
</item>

<!– Additional items go here –>

</channel>
</rss>

इस Example में, <channel> Element में Feed के बारे में Metadata Include है, और प्रत्येक <item> एक Individual Update या Entry को Represent करता है।

Implementation of RSS Feed in Web Page

RSS Feed को एक Web Page में Integrate करने के लिए, XML Data Receive और Parse करने के लिए JavaScript और AJAX का use कर सकते हैं।

Example:


<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title>RSS Feed Example</title>
</head>
<body>

<div id=”rss-feed”></div>

<script>
// Function to fetch and display RSS feed
function fetchRSSFeed() {
const feedUrl = ‘http://www.example.com/rss-feed.xml’;

// Use AJAX to fetch the RSS feed
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
// Parse XML response
const xmlDoc = xhr.responseXML;
const items = xmlDoc.getElementsByTagName(‘item’);

// Display each item in the RSS feed
for (let i = 0; i < items.length; i++) {
const title = items[i].getElementsByTagName(‘title’)[0].childNodes[0].nodeValue;
const link = items[i].getElementsByTagName(‘link’)[0].childNodes[0].nodeValue;
const description = items[i].getElementsByTagName(‘description’)[0].childNodes[0].nodeValue;

// Display the item in the web page
const feedContainer = document.getElementById(‘rss-feed’);
const itemElement = document.createElement(‘div’);
itemElement.innerHTML = `<h3>${title}</h3><p>${description}</p><a href=”${link}” target=”_blank”>Read more</a>`;
feedContainer.appendChild(itemElement);
}
}
};

xhr.open(‘GET’, feedUrl, true);
xhr.send();
}

// Call the function to fetch and display the RSS feed
fetchRSSFeed();
</script>

</body>
</html>

इस Example में, FetchRSSFeed Function RSS Feed Receive करने के लिए AJAX का use करता है, और फिर Defined HTML Container में प्रत्येक Item को Parse और Display करता है।

Tags: No tags

Add a Comment

Your email address will not be published. Required fields are marked *