AWD Unit 5
AWD Unit 5
class Program
{
static void Main()
{
// Create an XmlTextReader to read the XML file
using (XmlTextReader reader = new XmlTextReader("details.xml"))
{
// Read through the XML file
while (reader.Read())
{
// Check the node type and process accordingly
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "FirstName")
{
Console.WriteLine("First Name: " +
reader.ReadElementContentAsString());
}
else if (reader.Name == "LastName")
{
Console.WriteLine("Last Name: " +
reader.ReadElementContentAsString());
}
else if (reader.Name == "College")
{
Console.WriteLine("College: " +
reader.ReadElementContentAsString());
}
}
}
}
}
}
Xmltextwriter
Purpose: To create or modify XML documents.
Key Features:
>Provides methods to construct XML documents programmatically.
>Requires calling methods in the correct sequence to form a valid document.
>Starts with WriteStartDocument() and ends with WriteEndDocument().
>Allows nesting of elements using methods like WriteStartElement() and
WriteEndElement().
>Enables adding attributes to elements with WriteAttributeString().
>Supports indentation and formatting for better readability.
class Program
{
static void Main()
{
// Create an XmlTextWriter instance to write XML data to a file
using (XmlTextWriter writer = new XmlTextWriter("details.xml")
{
// Set formatting to indented for better readability
writer.Formatting = Formatting.Indented;
Explanation:
5. Writing XML:
o We use XmlTextWriter to write an XML document to a file named
details.xml.
o WriteStartElement starts a new element (like <Details>).
o WriteElementString adds child elements (like
<FirstName>John</FirstName>).
o Finally, WriteEndElement closes the elements, and
WriteEndDocument ends the XML document.
6. Reading XML:
o XmlTextReader reads the XML file details.xml.
o reader.Read() moves the reader to the next node.
o We check if the node is an element and then read the content of
elements like <FirstName>, <LastName>, and <College> using
ReadElementContentAsString().
7. Output of the Reader:
2)What is Xelement? Explain with an example.
Ans:
The `XElement` class in `System.Xml.Linq` represents an XML element.
`XElement` loads and parses XML. It allows us to remove a lot of old code and
reduces the chance of bugs and typing mistakes. The `XAttribute` class
represents an attribute of an element. The `XElement.Save` method saves the
content of an `XElement` to an XML file.
Example:
using System;
using System.Xml.Linq;
class Program
{
static void Main()
{
// XDocument का उपयोग करके XML दस्तावेज़ बनाना
XDocument doc = new XDocument(
new XElement("SuperProProductList",
new XElement("product",
new XAttribute("id", 1),
new XElement("name", "Super Pro 2000"),
new XElement("category", "Electronics"),
new XElement("price", 199.99)
),
new XElement("product",
new XAttribute("id", 2),
new XElement("name", "Super Pro 3000"),
new XElement("category", "Electronics"),
new XElement("price", 299.99)
)
)
);
- When a user tries to access a restricted page, it causes the browser to display
a login dialog box.
- It is supported by most browsers.
- It is configured through the IIS (Internet Information Services) management
console.
- It uses Windows user accounts and directory permissions to grant access to
restricted pages.
Advantages :
It keeps your password safe and uses encryption.
Users log in with their existing Windows account, so they don’t need to
remember multiple passwords.
All user accounts are managed in one place.
After logging in, user can use other apps without signing in again.
From developer's point of view, easy to implement.
Disadvantages:
It only works on Windows devices, so non-Windows users can’t use it easily.
If the server goes down, users can’t log in.
it’s hard to use with apps in the cloud.
If the server is hacked, all accounts are at risk.
2) **Forms-based authentication:**
- The developer creates a login form to collect the username and password.
- The username and password entered by the user are encrypted if the login
page uses a secure connection.
- It does not depend on Windows user accounts.
3) Windows Live ID authentication: ▪ It is centralized authentication service
offered by Microsoft. ▪ The advantage is that the user only has one maintain
one username and password.
file:///C:/Users/komal/Downloads/ITCS-AWP-converted.pdf 100
Nov 19
2) What is XML? What are its basic characteristics?
Ans: Defination of xml
XML stands for Extensible Markup Language. It is a commonly used format for
exchanging data because it is easy to read for both humans and machines.
If you have ever written a website in HTML, XML will feel familiar to you
because it is a stricter version of HTML.
XML uses tags, attributes, and values to structure data.
basic characteristics of xml
1)An XML element is made up of a **start tag** (like `<Name>`) and an **end
tag** (like `</Name>`). The content is placed between the start and end tags.
If we include a start tag, we must also include a matching end tag.
Another option is to create an **empty element**, where both the start and
end tags are combined with a **forward slash** at the end, and there is no
content (like `<Name />`).
This is similar to the syntax used in ASP.NET controls.
2) Whitespace between elements is ignored. That means we can freely use
tabs and hard returns to properly align(arrange) our information.
3) Hierarchical Structure:
XML organizes data in a tree structure, with elements inside other elements,
making it easy to represent complex data.
4) Supports All Languages:
XML can store data in any language because it supports Unicode.
5) Strict Rules:
XML follows strict rules—every tag must be closed properly, and tags must be
arranged correctly
6) Used for Data Sharing:
XML is commonly used to share data between different systems or store data
in a structured way.
7) Platform-Independent:
XML can be used on any system or device, making it universal.
8) Human and Machine Readable:
XML is written in plain text, which makes it easy for both people and
computers to read and process.
History of Ajax
Ajax was initially developed in 1999 by Microsoft Outlook Web Applications,
but its widespread use started 6 years later. The term Ajax was coined by Jesse
James Garrett in February 2005.
Before being called Ajax, it was known as XML HttpRequest Scripting Object
and operated using the MSXML Library.
Definiation of ajax
The full form of Ajax is Asynchronous JavaScript and XML.
It refers to a process where a user interacts with a web server using JavaScript
to send a request and display the response on the webpage without leaving or
reloading the current page.
Advantages :
. Reduces the server traffic and increases the speed.
2. Ajax is responsive and time taken is also less.
3. Form validation.
4. Bandwidth usage can be reduced.
5. Only update part of the page, no need to reload everything.
7. Sends only needed data, reducing server load.
8. Pages feel quick and smooth.
9. Runs on most devices and browsers.
10. esasy to use Works with HTML, CSS, and JavaScript.
Disaavantage of ajax:
1. If JavaScript is turned off in the browser, Ajax won’t work.
2. If the internet is slow, Ajax requests may fail or take longer.
3. Finding and fixing problems in Ajax code can be tricky.
4. Older browsers or less powerful devices might not support Ajax
fully, leading to functionality problems.
5. Ajax doesn't update the browser's history, so users can't use the
back or forward buttons easily.
6. Open-source.
3. Define Authentication and Authorization. Give types of Authentication.
ANS: Authentication and Authorization are two related security concepts.
Authentication is the process of verifying who the user is.
Authorization is the process of checking if the authenticated user has access
to the requested resources.
Example Usage:
<ajaxToolkit:Accordion ID="Accordion1" runat="server" SelectedIndex="0"
HeaderCssClass="accordion-header" ContentCssClass="accordion-content"
FadeTransitions="true" TransitionDuration="500" AutoSize="None">
<Panes>
<ajaxToolkit:AccordionPane>
<Header>Section 1</Header>
<Content>
<p>This is the content for section 1.</p>
</Content>
</ajaxToolkit:AccordionPane>
<ajaxToolkit:AccordionPane>
<Header>Section 2</Header>
<Content>
<p>This is the content for section 2.</p>
</Content>
</ajaxToolkit:AccordionPane>
</Panes>
</ajaxToolkit:Accordion>
Nov 22
using System;
using System.Xml.Linq;
class Program
{
static void Main()
{
// Create the XML structure using XElement
XElement employee = new XElement("employee",
new XElement("empId", 3),
new XElement("empName", "TS"), // Changed from cmpName to
empName
new XElement("empDept", "IT"), // Changed from empDep to empDept
new XElement("empDesignation", "MANAGER") // Changed from
cmpDesignation to empDesignation
);