You are on page 1of 13

1

Name: Registration No: Learning Centre: Learning Centre Code: Course: Applications (BCA) Subject: Semester: Module No: Date of Submission: Marks Awarded:

Bhawani Pratap Singh 520840181 Atmark Infotech 01669 Bachelor of Computer BC0053 VB .Net & XML 5th Semester I 20 November 2010

Signature of Signature of Coordinator Evaluator

Signature of Centre head

August 2010 Bachelor of Computer Application (BCA) Semester 5 BC0053 VB. Net & XML (Book ID: B0975) Assignment Set 1 (40 Marks) 4 Credits

Each question carries eight marks


application.

8 x 5 = 40

1. Describe the process of compiling and running a visual Basic

2. Explain various basic data types and variables in visual.

Answer: Data types There are two kinds of data types in VB.NET. 1. Value type (implicit data types, structure and enumeration) 2. Reference type (objects, delegates) Value types are passed to methods by passing an exact copy while reference types are passed to methods by passing only their reference. Implicit data types are defined in the language core by the language vendor, while explicit data types are types that are made by using or composing implicit data types. Each implicit data type in VB.NET has its corresponding .NET type. The implicit data types in VB.NET are VB.NET type Corresponding .Net Size in bytes Description

3 type Boolean Char

Boolean Char Integral types Byte Short Integer(default) Long Floating point types Single Double(default) Decimal

1 2

Contains either true or false Contains any single Unicode character enclosed in double quotes marks followed by a c. May contain integers from 0255 Ranges from -32,768 to 32,767 Ranges from -2,147,483,648 to 2,147,483,648 Ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,808 Ranges from 1.5*1045 to 3.4*1038 with 7 digits precision. With suffix f or F. ranges from 5.0*10345 to 1.7*10308 with 15-16 digits precision. Ranges from 1.0*1028 to 7.9*1028 with 28-29 digits precision. With suffix m or M

Byte Int16 Int32 Int64

1 2 3 8

Single Double Decimal

4 8 12

Implicit data types are represented in language using keywords, so each of above is a keyword in VB.Net. String is also an implicit data type in VB.net, so string is a keyword in VB.Net. Implicit data types are value types and thus stored at the stack, while user defined types or referenced types are stored at heap. Variables During the execution of program, data is temporarily stored in memory. A variable is the name given to a memory location holding particular type of data. So, each variable has associated with it a data type and value. In VB.NET a variable is declared as: Dim <variable> as <data type> Example Dim a As Integer

4 This will reserve an area of 4 bytes in memory to store integer type values, which will be referred in the rest of the program by identifier a. We can also initialize the variable as we declare it and also declare and intilize multiple variables of some types in a single statement. Dim isReady As Boolean = True Dim Percentage = 87.88, average = 43.9 A Single Dim digit As Char = 7c.
3. With the help of suitable example, describe the development of single document and multi-document interface.

4. With the help of suitable example describe the development of single document and multi-document interface.

5 .Explain the concept of setting a connection string with example.

Name: Registration No: Learning Centre: Learning Centre Code: Course: Applications (BCA) Subject: Semester: Module No: Date of Submission: Marks Awarded:

Bhawani Pratap Singh 520840181 Atmark Infotech 01669 Bachelor of Computer BC0053 VB .Net & XML 5th Semester II 20 November 2010

Signature of Signature of

Signature of

Coordinator Evaluator

Centre head

August 2010 Bachelor of Computer Application (BCA) Semester 5 BC0053 VB. Net & XML (Book ID: B0975) Assignment Set 2 (40 Marks) 4 Credits

Each question carries eight marks

8 x 5 = 40

1. What are syntax rules for writing XML file?

Answer: Syntax rules of XML are very simple and logical. XML consists of user defined tags. Ex: <address>Hyderabad</address> <state>AP</state> <city>HYD</city> We can describe the XML with the tags. In XML file each & every tag must have an ending tags. Ex:<student></student> To create the empty tags we use a single tag or a single line statement. <student></student>

7 XML is case sensitive. Ex: <student> </Student>. Invalid because starting element s is small and ending element S is capital. XML files without a root element cant be created. Ex: in the file student.xml <student> is the root element. <student> <sno>1</sno> <sname></sname> <saddr>Hyderabad</saddr> </student> In XML only proper nesting is used. Ex: valid XML file <student> <sno>1</sno> </student> Invalid XML file <student> <sno>1 </student> </sno> In XML, comments are used as follows <!- -comment- - > When declaring the attributes, each and every attribute value must be enclosed in the single quotes (or) double quotes. Ex: <student sno=1> </student> <student sno=1> </student> Element : an element consists of simple content consists of some text in between the tags. Ex: < address >this is address</address> Mixed content consists of simple content and attributes. Ex: <address attr= some_value>this is address</address> Complex content consists of another tag Ex: <student> <sno attr = some_value> Content -

8 </sno> </student> Ex: <student> <sno>1</sno> <sname>anu</sname> <marks>23</marks> <address>xyz</address> </student> Rules in creating the element names 1) Names with an underscore are nice: <first_name>, <last_name> 2) Names should be short and simple: <std_name> and not <nam_of_the_std>. 3) Avoid _ characters. If some element is named as first_name. some softwares may try to subtract name from first. 4) Avoid : characters. Colons are reserved to be used for something called name spaces. 5) Avoid . characters. If an element is named as first.name then some softwares may think that name is a property of the object first.

2. Explain XML entities.

Answer: Entities are variables used to define shortcuts to standard text or special characters. - Entity references are references to entities. - entities can be declared internal or external. Some characters have a special meaning in XML, like the less than sign (<) that defines the start of an XML tag. The following entities are predefined in XML: Entity references &it; &gt; &amp; &quot; &apos; Character < > &

Internal entity declaration:

9 These types of entities are declared in DTD document and accessed in the XML document. Here the content that the entity has to represent is specified in declaration part of the entity i.e. within the DTD document, thus these types of entities are known as internal entities.

Syntax: <!ENTITY entity_name entity_value> Syntax to refer the entity: & entity_name; DTD example: <!ENTITY writer hai> <!ENTITY copyright copyright.yahoo> Valid XML example: <author> &writer; &copyright; </author> External entity declaration: In this case the content that is to be referred by entity is placed into separate document instead of specifying into the same document. Syntax: <! ENTITY entity_name SYSTEM file path locating the document containing the content to refer> Example: <! ENTITY writer SYSTEM entities.dtd> XML example: <author> &writer; </author>

3. What are the methods and properties of XML DOM? Explain with examples.

Answer: XML DOM properties

10 - Properties and methods define the programming interface to the XML DOM. - The DOM models XML as a set of node objects. The nodes can be accessed with JavaScript or other programming languages. - The programming interface to the DOM is defined by a set standard properties and methods. XML DOM methods i) x.getChildNodes returns a list of all of the children of the current node. This is returned as a node list object which has its own methods. ii) x.getFirstChild returns the 1st child of the current node. iii) x.getLastChild returns the last child of the current node. iv) x.getPreviousSibling returns the node immediately before the current node. v) x.getNextSibling returns the node immediately after the current node. vi) x.getAttributes returns a NamedNodeMap containing the attributes of the current node. vii) x.insertBefore (newnode, refnode) inserts the new node immediately before the current node which is passed as the refnode parameter. viii) x.replaceNode (newnode, oldnode) replaces the node in its second parameter with that in its first. ix) x.removeChild (child) removes the child node from the tree. x) x.appendChild (child) appends the child to the end of the list of children of the current node. xi) x.getElementsByTagName (tag) returns all elements which have the name supplied as a parameter. To return all of the elements in a tree we use the parameter *. The parameter is a string which must be quoted. Some typical DOM properties ~ x.nodeName the name of x. ~ x.nodeValue the value of x. ~ x.parentNode the parent node of x. ~ x.childNodes the child nodes of x. ~ x.attributes the attributes. In the entire above list, x is a node object.

11 Example: access a node using its index number in a node list. It uses the getElementsByTagName() method to get the second <sname> element in college.xml <html> <head> <script type = text/javascript src = loadxmldoc.js></script> </head> <body> <script type = text/javascript> xmlDoc = loadXMLDoc(college.xml); x=xmlDoc. getElementsByTagName(sname); document.write(x[2].childNodes[0].nodeValue); </script> </body> </html> Output Rani

4. Explain XML schema. What are the disadvantages of DTD?

Answer: XML Schema includes constructors that help us to prepare XML markup language specifications, alternative to DTD. The XML Schema language is also referred to as XML Schema Definition (XSD). - XML Schemas are extensible to future additions. - XML Schemas are richer and more powerful than DTDs. - XML Schemas are written in XML. - XML Schemas support data types. - XML Schemas support namespaces. An XML Schema instances is an XML Schema Definition (XSD) and typically has the filename extension .xsd. The language itself is sometimes informally referenced as XSD. Disadvantages # While specifying the child elements in DTD it can only use /, * or + to describe the occurrences. But in most of the cases we want to describe the exact number for the lower and

12 upper limit. Like we may want the emps element to have minimum 5 emp elements and maximum 20. # DTD does not have a support for common and simple types instead it provides only PCDATA. # DTD does not support XML languages. # in case of DTD the element definition, name and the element name is same.

5. What is XPath ? Explain XPath string functions with examples?

Answer: XPATH ~ XPath specification is a part of xml specification. ~ XPath specifications include some constructs to build paths, expressions and include some functions for string and operations. ~ These specifications can be used in XSL. ~ XPath is a major element in XSLT. ~ XPath is a w3c recommendation. XPath String functions 1. substring (string, startindex, len) 2. substring before (string1 string2) Example substring before (abc, b). it returns a. 3. substring after (string1 string2) Example substring before (abc,b). it returns c. 4. contains (string1, string2): Returns Boolean. This returns true if string2 appears in string1, otherwise false. 5. Start with (string1, string2); Example: start with (abc, ab). It returns true. 6. string length (string): it returns the length of a string. 7. normalize space (string): returns the input string after normalizing the white space, which includes eliminating white spaces in beginning and ending and remove multiple white space identified in between of the string, replacing with a single white space.

13 Example: - - abc - -xyz -. Here the dashes (-) are white spaces. Output: abc-xyz.

6. What is DOM? Draw the DOM tree for emp.xml.

Answer The XML Document object mode (DOM) is a programming interface for XML documents. It defines the way an XML document can be accessed and manipulated. The XML DOM is a W3C recommendation. The DOM says 1) The entire document is a document node. 2) Every XML element is an element node. 3) The texts in the XML elements are text nodes. 4) Every attribute is an attribute node. 5) Comments are comment nodes. XML DOM defines the objects and properties of all XML elements and the methods (interface) to access them. The XML DOM is a standard for how to get, change, add or delete XML elements. The XML DOM views an XML document as tree-structure. The tree structure is called a node tree. All nodes can be accessed through the tree. Their contents can be modified or deleted and new elements can be created. The node tree shows the set of nodes and the connections between them. The tree starts at the root node and branches out to the next nodes at the lowest level of the tree. DOM tree for emp.xml
Root element <emp>

parent
Attribute: department Element: <eaddr>

Attribute: firstname

Element: <employees>

child
Element: <edept>

Element: <ename>

Element: <eno>

Text: Shayam.

Text: 100

Text: Sales.

Text: Gurgaon.

You might also like