Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Sunday, 19 December 2010

4. Explain what a diffgram is and its usage ?

A DiffGram is an XML format that is used to identify current and original versions of data elements. The DataSet uses the DiffGram format to load and persist its contents, and to serialize its contents for transport across a network connection. When a DataSet is written as a DiffGram, it populates the DiffGram with all the necessary information to accurately recreate the contents, though not the schema, of the DataSet, including column values from both the Original and Current row versions, row error information, and row order.
When sending and retrieving a DataSet from an XML Web service, the DiffGram format is implicitly used. Additionally, when loading the contents of a DataSet from XML using the ReadXml method, or when writing the contents of a DataSet in XML using the WriteXml method, you can select that the contents be read or written as a DiffGram.

What is DOM and how does it relate to XML?

The Document Object Model (DOM) is an interface specification maintained
by the W3C DOM Workgroup that defines an application independent
mechanism to access, parse, or update XML data. In simple terms
it is a hierarchical model that allows developers to manipulate
XML documents easily Any developer that has worked extensively with
XML should be able to discuss the concept and use of DOM objects
freely. Additionally, it is not unreasonable to expect advanced
candidates to thoroughly understand its internal workings and be
able to explain how DOM differs from an event-based interface like
SAX.

Difference between XML and HTML

1) XML is not a replacement for HTML.
2) XML and HTML were designed with different goals.
3) XML was designed to describe data and to focus on what data is.
4) HTML was designed to display data and to focus on how data looks.
5) HTML is about displaying information, XML is about describing information

XML

User definable tags
Content driven
End tags required for well formed documents
Quotes required around attributes values
Slash required in empty tags

HTML
Defined set of tags designed for web display
Format driven
End tags not required
Quotes not required
Slash not required

What is XML?

XML is the Extensible Markup Language. It improves the functionality
of the Web by letting you identify your information in a more accurate,
flexible, and adaptable way. It is extensible because it is not
a fixed format like it�s written in SGML, the international standard meta language for
text document markup (ISO 8879).

Thursday, 16 December 2010

How does the XmlSerializer work?

Click Here to View Latest ASP.Net Questions

XmlSerializer in the .NET Framework is a great tool to convert Xml into runtime objects and vice versa
If you define integer variable and an object variable and a structure then how those will be plotted in memory.
Integer , structure � System.ValueType -- Allocated memory on stack , infact integer is primitive type recognized and allocated memory by compiler itself .
Infact , System.Int32 definition is as follows :

Click Here to View Latest ASP.Net Questions

Thursday, 5 November 2009

What are the different kind of parsers used in XML?

There are 2 parsers:
1) DOM (Document object model): This will interpret Complete XML document.Microsoft major concentration is DOM Parser.
2) SAX Parser (Simple Aplication programming Interface for XML): This will interpret XML document based on the event occurrence only it wont interpret complete document at a time. Sun mycrosystems major concentration is SAX Parser.What is XPath?
XPath is used to navigate through elements and attributes in an XML document.

Saturday, 22 November 2008

Reading and writing to an XML file.

Click here for all C# Interview Questions

Click here for all ASP.NET Interview Questions


Create a simple web page, that can read and write to an XML file. The XML file has a list of email ids. The sample web form should have the following functionality. You have 30 minutes to code and test.

1. A TextBox to accept a valid email id.

2. A submit button. When you click the submit button, the email id entered in the TextBox must be saved to the XML file.

3. If I donot enter anything in the TextBox and click the submit button, the application should show a validation message stating "Email is required".

4. If I enter an invalid email, the application should show a message "Invalid Email".

5. If javascript is enabled the validation should happen on the client browser without postback. If javascript is disabled the validation should happen on the web server.

6. Finally we should have a list box, which will show all the existing email ids in the XML file. When you submit a new email, the listbox should be reloaded showing the newly added email along with already existing email ids.

Answer:
1. Create a webform and add a TextBox, RequiredFieldValidator, RegularExpressionValidator, Button and a ListBox.

2. Set the RequiredFieldValidator "ErrorMessage" property to "Email Required" and "ControlToValidate" property to "EmailTextBox" and "Display" property to "Dynamic" as shown below.
<asp:RequiredFieldValidator ID="EmailRequiredFieldValidator" runat="server" ErrorMessage="Email Required" ControlToValidate="EmailTextBox" Display="Dynamic"></asp:RequiredFieldValidator>

3. Set the RegularExpressionValidator "ErrorMessage" property to "Invalid Email" and "ControlToValidate" property to "EmailTextBox" and "Display" property to "Dynamic" as shown below.
<asp:RegularExpressionValidator ID="EmailRegularExpressionValidator" runat="server" ErrorMessage="Invalid Email" ControlToValidate="EmailTextBox" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>

4. Set the ListBox, "DataTextField" property to "Email" and DataValueField property to "Email"

5. The complete HTML of the web form should be as shown below.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<html>
<head runat="server">
<title>Email List</title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
Please enter a valid email:
</td>
<td>
<asp:TextBox ID="EmailTextBox" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="EmailRequiredFieldValidator" runat="server" ErrorMessage="Email Required" ControlToValidate="EmailTextBox" Display="Dynamic"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="EmailRegularExpressionValidator" runat="server" ErrorMessage="Invalid Email" ControlToValidate="EmailTextBox" Display="Dynamic" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" /></td>
</tr>
</table>
<br />
Existing Email Ids
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="292px" Width="192px" DataTextField="Email" DataValueField="Email"></asp:ListBox>
</form>
</body>
</html>

6. Place the XML file that contains the list of email ids in the root folder of the web application. The sample XML file is shown below.
<?xml version="1.0" standalone="yes"?>
<EmailsList>
<Emails>
<Email>dhex@yahoo.com</Email>
</Emails>
<Emails>
<Email>dmexy@aol.com</Email>
</Emails>
<Emails>
<Email>dpitt@gmail.com</Email>
</Emails>
<Emails>
<Email>mston@microsoft.com</Email>
</Emails>
</EmailsList>

7. In the code behind file, write a function the can read the email ids from the XML file into a DataSet. Set this DataSet as the DataSource for the ListBox and call the DataBind() method. The function should be as shown below.
private void LoadExistingEmails()
{
DataSet DS = new DataSet();
DS.ReadXml(Server.MapPath("Emails.xml"));

ListBox1.DataSource = DS;
ListBox1.DataBind();
}

8. Call the above LoadExistingEmails() function in the Page_Load event handler as shown in the sample code below.
protected void Page_Load(object sender, EventArgs e)
{
LoadExistingEmails();
}

9. Finally, when you click the submit button write to the XML file as shown below.
protected void Button1_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
DataSet DS = new DataSet();
DS.ReadXml(Server.MapPath("Emails.xml"));

DataRow DR = DS.Tables[0].NewRow();
DR["Email"] = EmailTextBox.Text;

DS.Tables[0].Rows.Add(DR);

DS.WriteXml(Server.MapPath("Emails.xml"));
LoadExistingEmails();
}
}

Points to remember:
1.
Validation controls work both on the client and on the server.

2. If javascript is enabled validations happen on the client browser without posting the page back to the server.

3. If javascript is disabled, validations happen on the server. To check if all the validation controls haved passed validation, use Page.IsValid property.

4. Page.IsValid returns "true" if the page has succeeded validation and "false" even if a single validation control has filed validation.

5. In our example, we write to the XML file only if Page.IsValid property returns true.

Testing the sample application:To test if the validation controls are working on the server, disable javascript on the client browser. To disable javascript on the client browser follow the below steps.
1. Open internet explorer.

2. Click on Tools.

3. Click on Internet Options. You will see Internet Options dialog page.

4. Click on the Security tab.

5. On the Security tab, select Local intranet under Select a zone to view or change security settings.

6. Click "Custom Level" button under "Security Level for this zone"

7. On the "Security Setting - Local Intranet Zone" dialog page, scroll down to "Scripting" section.

8. Select "Disable" radio button under "Active scription" and click "OK" button.

Wednesday, 12 November 2008

XML Interview Questions

What determines the validity of an XML document?
Document Type Definition(DTD) or an XML Schema determines the validity of an XML document.

What is a valid XML document?XML documents are compared to rules that are specified in a DTD or schema. A well-formed XML document that meets all of the requirements of one or more specifications is called a valid XML Document.

What are the 2 types of XML parsers?
Nonvalidating Parsers - Parsers that don�t support validation
Validating Parsers - Parsers that support validation

Can you combine both Schema and DTD references in a single XML document?Yes

Are DTD's well-formed XML documents?
No, DTDs are not well-formed XML documents. This is because they follow DTD syntax rules rather than XML document syntax.

Are XML schema's well-formed XML documents?Yes.

What is the difference between an XML schema and a DTD?
The XML Schema is the officially sanctioned Schema definition. Unlike DTDs, the format of XML Schemas follows the rules of well-formed XML documents. The Schema also allows for much more granular control over the data that is being described. Because of the XML format and the detailed format controls, Schemas tend to be very complex and often much longer than the XML documents that they are describing. Schemas are often much more easy for developers to read and follow,due to the less cryptic nature of the references in Schemas versus DTDs.

How do you define references to schemas in an XML document?References to schemas are defined by creating an instance of the XMLSchemainstance namespace. An example is shown below.
<rootelement xmlns:xsi=�http://www.w3.org/2001/XMLSchemainstance� xsi:noNamespaceSchemaLocation=�schemafile.xsd�>

The namespace declaration reference to http://www.w3.org/2001/XMLSchemainstance resolves to an actual document at that location, which is a brief description of the way that the W3C Schema should be referenced. The noNamespaceSchemaLocation value tells us that there is no predefined namespace for the Schema. This means that all of the elements in the XML document should be validated against the schema specified. The location of the Schema is schemafile.xsd. Because there is no path defined, the file containing the schema should be located in the same directory as the XML file to be validated by the Schema.

You can also define the schema location, and map it to a specific namespace by using the schemaLocation attribute declaration instead of noNamespace SchemaLocation. If you do so, you have to declare a namespace that matches the schemaLocation attribute value. The declaration must be made before you reference the schema in a schemaLocation attribute assignment.

Tuesday, 11 November 2008

XML related Interview Questions

Click here for all C# Interview Questions

Click here for all ASP.NET Interview Questions

What Is XML?

XML stands for Extensible Markup Language, and it is used to describe documents and data in a standardized, text-based format that can be easily transported via standard Internet protocols. XML, like HTML, is based on, Standard Generalized Markup Language (SGML).

What are Well-formed XML documents?
XML
, is very strict about a small core of format requirements that make the difference between a text document containing a bunch of tags and an actual XML document. XML documents that meet W3C XML document formatting recommendations are described as being well-formed XML documents. Well-formed XML documents can contain elements, attributes, and text.

What is an empty XML element?
Elements with no attributes or text are called as empty XML element. Empty XML elements can be represented in an XML document as shown below:
<element/>

What is meant by XML document declaration?Most XML documents start with an <?xml?> element at the top of the page. This is called an XML document declaration. An XML document declaration is an optional element that is useful to determine the version of XML and the encoding type of the source data. It is not a required element for an XML document to be well formed. Most common XML document declaration is shown below:
<?xml version=�1.0� encoding=�UTF-8�?>

What does UTF stands for?
UTF stands for Universal Character Set Transformation Format.

Should every XML document have a root element?Yes.

Can an XML document contain multiple root level elements?
No, an XML document can contain only one root level element.

What is the use of XML attributes?XML attributes are used for adding more information and descriptions to the values of elements,and the text associated with elements.

Is XML case sensitive?
Yes

How do you comment lines in XML?You can comment lines in XML as shown below.
<! -- This is commented line in an XML document -->

What are XML namespaces?
Namespaces are a method for separating and identifying duplicate XML element names in an XML document. Namespaces can also be used as identifiers to describe data types and other information. Namespace declarations can be compared to defining a short variable name for a long variable (such as pi=3.14159....) in programming languages. In XML, the variable assignment is defined by an attribute declaration. The variable name is the attribute name, and the variable value is the attribute value. In order to identify namespace declarations versus other types of attribute declarations, a reserved xmlns: prefix is used when declaring a namespace name and value. The attribute name after the xmlns: prefix identifies the name for the defined namespace. The value of the attribute provides the unique identifier for the namespace. Once the namespace is declared, the namespace name can be used as a prefix in element names.

Why is it a good idea to use a URL as the XML namespace value?
Although the namespace declaration value does not need to be a URL or resolve to an actual URL destination, it is a good idea to use a URL anyway, and to choose a URL that could resolve to an actual destination, just in case developers want to add documentation for the namespace to the URL in the future.

When to use namespaces?Namespaces are optional components of basic XML documents. However, namespace declarations are recommended if your XML documents have any current or future potential of being shared with other XML documents that may share the same element names. Also, newer XML-based technologies such as XML Schemas,SOAP, and WSDL make heavy use of XML namespaces to identify data encoding types and important elements of their structure.


Click here for all C# Interview Questions

Click here for all ASP.NET Interview Questions

Tuesday, 9 January 2007

What is the use of XSLT?

XSLT stands for Extensible Stylesheet Language Transformations. This language used in XSL style sheets to transform XML documents into other XML documents.XSLT is based on template rules which specify how XML documents should be processed. An XSLT processor reads both an XML document and an XSLT style sheet. Based on the instructions the processor finds in the XSLT style sheet, it produce a new