XML

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

ii) Describe about the eXtensible Markup Language (XML) Namespace.

(5 marks)
XML Namespace: (Definition---
1mark)
A Namespace is a set of unique names. Namespace is a mechanisms by which element and
attribute name can be assigned to a group. The Namespace is identified by URI(Uniform Resource
Identifiers).
Namespace Declaration --------
1mark
A Namespace is declared using reserved attributes. Such an attribute name must either be
xmlns or begin with xmlns: shown as below −
<element xmlns:name = "URL">
Syntax --------
1mark
 The Namespace starts with the keyword xmlns.
 The word name is the Namespace prefix.
 The URL is the Namespace identifier.
Example --------
1mark
Namespace affects only a limited area in the document. An element containing the declaration and
all of its descendants are in the scope of the Namespace. Following is a simple example of XML
Namespace −
<?xml version = "1.0" encoding = "UTF-8"?>
<cont:contact xmlns:cont = "www.tutorialspoint.com/profile">
<cont:name>Tanmay Patil</cont:name>
<cont:company>TutorialsPoint</cont:company>
<cont:phone>(011) 123-4567</cont:phone>
</cont:contact>

Multiple Namespaces: --------


1mark
Use more than one xmlns declaration, like this:
<foo:tag xmlns:foo="http://me.com/namespaces/foofoo"
xmlns:bar="http://me.com/namespaces/foobar" >
<foo:head>
<foo:title>An example document</foo:title>
</foo:head>
<bar:body>
<bar:e1>a simple document</bar:e1>
<bar:e2>
Another element
</bar:e2>
</bar:body>
</foo:tag>

iii) Create an eXtensible Markup Language (XML) schema for the below XML document:

(6marks)
<?xml version = “1.0”?>
<book>
<title> XML in a Nutshell </title>
<author> Harold </author>
</book>
<?xml version = "1.0" encoding = "UTF-8"?>

XML SCHEMA: program:6marks


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

You might also like