0% found this document useful (0 votes)
22 views21 pages

Module 3

This document covers the creation and manipulation of XML documents using .NET, including XML elements, attributes, and serialization. It also discusses networking concepts, web services, and provides examples of searching nodes in various data structures. Additionally, it introduces XPath for navigating XML documents and explains different axes used in XPath expressions.

Uploaded by

deepthijha005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views21 pages

Module 3

This document covers the creation and manipulation of XML documents using .NET, including XML elements, attributes, and serialization. It also discusses networking concepts, web services, and provides examples of searching nodes in various data structures. Additionally, it introduces XPath for navigating XML documents and explains different axes used in XPath expressions.

Uploaded by

deepthijha005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

XML, Networking, and Web Services

with .NET
MODULE - 3 XML, Networking, and 22CSE451.3 8 Hours
Web Services with .NET

Working with XML: Creating XML Documents –XML Elements -XML


Attributes -Searching for a Single Node - Search Axes -Where Clauses –
XML Serialization – Networking-Web Application with Client-Side Code –
.NET Client and .NET Server -.NET Client and External Party Web Service
-External Client and .NET Web Service - WCF-Creating a WCF Project –
Hosting a WCF Service.
Creating XML Documents

To create XML documents in Visual Studio Code, you can follow these
steps:

• Open Visual Studio Code : Launch Visual Studio Code on your computer.

• Create a New File : Click on "File" in the menu bar, then select "New File" to
create a new fi le.

• Save the File with ".xml" Extension : Save the newly created fi le with a
".xml" extension. You can do this by clicking on "File" > "Save As" and then
providing a fi le name with the ".xml" extension.

• Start Writing XML : Once the fi le is created and saved, you can start writing
your XML content. You can use XML syntax to structure your data as needed.

• Edit and Save : You can continue editing your XML document as needed.
Remember to save your changes regularly.
Syntax

<?xml version="1.0" encoding="UTF-8"?>


<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<?xml version="1.0"?>

<Company>

<Employee>

<FirstName>Tanmay</FirstName>

<LastName>Patil</LastName>

<ContactNo>1234567890</ContactNo>

<Email>[email protected]</Email>

<Address>

<City>Bangalore</City>

<State>Karnataka</State>

<Zip>560212</Zip>

</Address>

</Employee>
What is an XML Element?
An XML element is everything from (including) the element's start tag to

(including) the element's end tag.

<price>29.99</price>

An element can contain:

•text

•attributes

•other elements

•or a mix of the above


<bookstore>
<book category="children">
<title>Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title>Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year> In the example above:
<price>39.95</price>
<title>, <author>, <year>, and <price> have text
</book> content because they contain text (like 29.99).
</bookstore>
<bookstore> and <book> have element contents,
because they contain elements.

<book> has an attribute (category="children").


Empty XML Elements

An element with no content is said to be empty.

In XML, you can indicate an empty element like this:

<element></element>
XML Attributes
XML elements can have attributes, just like HTML.

Attributes are designed to contain data related to a specifi c element.

XML Attributes Must be Quoted

Attribute values must always be quoted. Either single or double quotes can be
used.

For a person's gender, the <person> element can be written like this:

<person gender="female">

Or

<person gender='female'>
If the attribute value itself contains double quotes you can use
single quotes, like in this example:

<gangster name=‘NHCE “affiliated" College’>


XML Elements vs. Attributes

Take a loo k at these two examp les:

<person gender ="female">


<firstname >Anna</firstname >
<lastname >Smith</lastname >
</person >

<person >
<gender >female </gender >
<firstname >Anna</firstname >
<lastname >Smith</lastname >
</person >

In the first example, gender is an attribute. In the last example, gender is an element. Both examples
provide the same information.
There are no rules about when to use attributes or when to use elements in XML.
Searching for a Single Node
Searching for a single node in a data structure using C# can vary depending on the type of data structure
you are dealing with. Here are steps for searching a single node in three common data structures: a binary
search tree (BST), a linked list, and a graph using depth-first search (DFS).

1. Binary Search Tree (BST)

Steps:

Start at the root node.

Compare the target value with the value of the current node.

If they are equal, you have found the node.

If the target value is less than the current node's value, move to the left child and repeat from step 2.

If the target value is greater than the current node's value, move to the right child and repeat from step 2.

If you reach a null node, the target value is not in the tree.
2. Linked List

Steps:

Start at the head of the list.

Compare the target value with the value of the current node.

If they are equal, you have found the node.

If not, move to the next node and repeat from step 2.

If you reach the end of the list (null node), the target value is not in the
list.
3. Graph (using Depth-First Search)

Steps:

Start at the given node.

Mark the node as visited.

Compare the target value with the value of the current node.

If they are equal, you have found the node.

If not, recursively search each adjacent (neighbor) node that has not been
visited yet.

If all nodes connected to the start node are visited and the target node is not
found, it does not exist in the graph.
Search Axes
In XML, XPath (XML Path Language) is used to navigate through elements and attributes

in an XML document.

XPath uses a variety of expressions, including axes, to locate specific parts of an XML document.

Axes allow you to specify the direction of navigation relative to the current node.

Here are some common axes used in XPath:

1. Child Axis (/) : Selects all child nodes of the current node.

Example: /bookstore/book selects all <book> elements that are children of the <bookstore> element.

2. Parent Axis (..) : Selects the parent of the current node.

Example: ../title selects the <title> element that is a parent of the current node.

3. Attribute Axis (@) : Selects the attributes of the current node.

Example: @lang selects the lang attribute of the current node.

4. Self Axis (self::) : Selects the current node itself.

Example: self::book selects the current node if it is a <book> element.


Descendant Axis (//): Selects all descendants (children, grandchildren, etc.) of the current
node.
Example: //author selects all <author> elements in the document.

Ancestor Axis (ancestor::): Selects all ancestors (parent, grandparent, etc.) of the current
node.
Example: ancestor::bookstore selects the <bookstore> element if it is an ancestor of the
current node.

Following Axis (following::): Selects all nodes that come after the current node in
document order.
Example: following::book selects all <book> elements that come after the current node.

Preceding Axis (preceding::): Selects all nodes that come before the current node in
document order.
Example: preceding::book selects all <book> elements that come before the current node.

You might also like