SlideShare ist ein Scribd-Unternehmen logo
1 von 47
1
XML
Mrs.C.Santhiya
Assistant Professor
TCE,Madurai
2
XML is not…
• A replacement for HTML
(but HTML can be generated from XML)
• A presentation format
(but XML can be converted into one)
• A programming language
(but it can be used with almost any language)
• A network transfer protocol
(but XML may be transferred over a network)
• A database
(but XML may be stored into a database)
3
XML by Example
<article>
<author>Gerhard Weikum</author>
<title>The Web in 10 Years</title>
</article>
• Easy to understand for human users
• Very expressive (semantics along with the data)
• Well structured, easy to read and write from programs
This looks nice, but…
4
XML by Example
<t108>
<x87>Gerhard Weikum</x87>
<g10>The Web in 10 Years</g10>
</t108>
• Hard to understand for human users
• Not expressive (no semantics along with the data)
• Well structured, easy to read and write from programs
… this is XML, too:
5
XML by Example
<data>
ch37fhgks73j5mv9d63h5mgfkds8d984lgnsmcns983
</data>
• Impossible to understand for human users
• Not expressive (no semantics along with the data)
• Unstructured, read and write only with special programs
… and what about this XML document:
The actual benefit of using XML highly depends
on the design of the application.
6
Possible Advantages of Using XML
• Truly Portable Data
• Easily readable by human users
• Very expressive (semantics near data)
• Very flexible and customizable (no finite tag set)
• Easy to use from programs (libs available)
• Easy to convert into other representations
(XML transformation languages)
• Many additional standards and tools
• Widely used and supported
7
A Simple XML Document
<article>
<author>Gerhard Weikum</author>
<title>The Web in Ten Years</title>
<text>
<abstract>In order to evolve...</abstract>
<section number=“1” title=“Introduction”>
The <index>Web</index> provides the universal...
</section>
</text>
</article>
Freely definable tags
8
Element
Content of
the Element
(Subelements
and/or Text)
A Simple XML Document
<article>
<author>Gerhard Weikum</author>
<title>The Web in Ten Years</title>
<text>
<abstract>In order to evolve...</abstract>
<section number=“1” title=“Introduction”>
The <index>Web</index> provides the universal...
</section>
</text>
</article>
End Tag
Start Tag
9
A Simple XML Document
<article>
<author>Gerhard Weikum</author>
<title>The Web in Ten Years</title>
<text>
<abstract>In order to evolve...</abstract>
<section number=“1” title=“Introduction”>
The <index>Web</index> provides the universal...
</section>
</text>
</article>
Attributes with
name and value
10
Elements in XML Documents
• (Freely definable) tags: article, title, author
– with start tag: <article> etc.
– and end tag: </article> etc.
• Elements: <article> ... </article>
• Elements have a name (article) and a content (...)
• Elements may be nested.
• Elements may be empty: <this_is_empty/>
• Element content is typically parsed character data (PCDATA),
i.e., strings with special characters, and/or nested elements (mixed
content if both).
• Each XML document has exactly one root element and forms a
tree.
• Elements with a common parent are ordered.
11
Elements vs. Attributes
Elements may have attributes (in the start tag) that have a name
and
a value, e.g. <section number=“1“>.
What is the difference between elements and attributes?
• Only one attribute with a given name per element (but an
arbitrary number of subelements)
• Attributes have no structure, simply strings (while elements can
have subelements)
As a rule of thumb:
• Content into elements
• Metadata into attributes
Example:
<person born=“1912-06-23“ died=“1954-06-07“>
Alan Turing</person> proved that…
12
XML Documents as Ordered Trees
article
author title text
sectionabstract
The index
Web
provides …
title=“…“
number=“1“
In order …
Gerhard
Weikum
The Web
in 10 years
13
More on XML Syntax
• <root>  <child>    <subchild>.....</subchild>  </child></root>
• <?xml version="1.0" encoding="UTF-8"?>
• XML Tags are Case Sensitive
• XML Elements Must be Properly Nested
• XML Attribute Values Must be Quoted
• <!-- This is a comment -->
• Some special characters must be escaped using entities:
< →  &lt;
& →  &amp;
(will be converted back when reading the XML doc)
• Some other characters may be escaped, too:
> →  &gt;
“ →  &quot;
‘ →  &apos;
14
Well-Formed XML Documents
A well-formed document must adher to, among others, the 
following rules:
• Every start tag has a matching end tag.
• Elements may nest, but must not overlap.
• There must be exactly one root element.
• Attribute values must be quoted.
• An element may not have two attributes with the same 
name.
• Comments and processing instructions may not appear 
inside tags.
• No unescaped < or & signs may occur inside character 
data.
15
Well-Formed XML Documents
A well-formed document must adher to, among others, the 
following rules:
• Every start tag has a matching end tag.
• Elements may nest, but must not overlap.
• There must be exactly one root element.
• Attribute values must be quoted.
• An element may not have to attributes with the same 
name.
• Comments and processing instructions may not appear 
inside tags.
• No unescaped < or & signs may occur inside character 
data.
Only well-formed documents
can be processed by XML
parsers.
16
Namespace Syntax
<dbs:book xmlns:dbs=“http://www-dbs/dbs“>
Unique URI to identify
the namespace
Signal that namespace 
definition happens
Prefix as abbrevation
of URI
17
Namespace Example
<dbs:book xmlns:dbs=“http://www-dbs/dbs“>
<dbs:description> ... </dbs:description>
<dbs:text>
<dbs:formula>
<mathml:math
xmlns:mathml=“http://www.w3.org/1998/Math/MathML“>
...
</mathml:math>
</dbs:formula>
</dbs:text>
</dbs:book>
18
Default Namespace
• Default namespace may be set for an element and its 
content (but not its attributes):
<book xmlns=“http://www-dbs/dbs“>
<description>...</description>
<book>
• Can be overridden in the elements by specifying the 
namespace there (using prefix or default namespace)
19
3.1 Document Type Definitions
Sometimes XML is too flexible:
• Most Programs can only process a subset of all possible XML applications
• For exchanging data, the format (i.e., elements, attributes and their semantics) must be fixed
⇒ Document Type Definitions (DTD) for establishing the vocabulary for one XML application (in 
some sense comparable to schemas in databases)
A document is valid with respect to a DTD if it conforms to the rules specified in that DTD.
Most XML parsers can be configured to validate.
<!DOCTYPE element DTD identifier 
[ declaration1 declaration2 ........ ]>
20
DTD Example: Elements
<!ELEMENT article (title,author+,text)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT text (abstract,section*,literature?)>
<!ELEMENT abstract (#PCDATA)>
<!ELEMENT section (#PCDATA|index)+>
<!ELEMENT literature (#PCDATA)>
<!ELEMENT index (#PCDATA)>
Content of the title element
is parsed character data
Content of the article element is a title element,
followed by one or more author elements,
followed by a text element
Content of the text element may
contain zero or more section
elements in this position
21
Element Declarations in DTDs
One element declaration for each element type:
<!ELEMENT element_name content_specification>
where content_specification can be
• (#PCDATA)  parsed character data
• (child)  one child element
• (c1,…,cn) a sequence of child elements c1…cn
• (c1|…|cn) one of the elements c1…cn
For each component c, possible counts can be specified:
– c exactly one such element
– c+  one or more
– c*  zero or more
– c?  zero or one 
Plus arbitrary combinations using parenthesis:
<!ELEMENT f ((a|b)*,c+,(d|e))*>
22
More on Element Declarations
• Elements with mixed content:
<!ELEMENT text (#PCDATA|index|cite|glossary)*>
• Elements with empty content:
<!ELEMENT image EMPTY>
• Elements with arbitrary content (this is nothing for 
production-level DTDs):
<!ELEMENT thesis ANY>
23
Attribute Declarations in DTDs
Attributes are declared per element:
<!ATTLIST section number CDATA #REQUIRED
title CDATA #REQUIRED>
declares two required attributes for element section.
element name
attribute name
attribute type
attribute default
24
Attribute Declarations in DTDs
Attributes are declared per element:
<!ATTLIST section number CDATA #REQUIRED
title CDATA #REQUIRED>
declares two required attributes for element section.
Possible attribute defaults:
• #REQUIRED is required in each element instance
• #IMPLIED is optional
• #FIXED default always has this default value
• default has this default value if the attribute is
omitted from the element instance
25
Attribute Types in DTDs
• CDATA string data
• (A1|…|An) enumeration of all possible values of the
attribute (each is XML name)
• ID unique XML name to identify the element
• IDREF refers to ID attribute of some other element
(„intra-document link“)
• IDREFS list of IDREF, separated by white space
• plus some more
26
Attribute Examples
<ATTLIST publication type (journal|inproceedings) #REQUIRED
pubid ID #REQUIRED>
<ATTLIST cite cid IDREF #REQUIRED>
<ATTLIST citation ref IDREF #IMPLIED
cid ID #REQUIRED>
<publications>
<publication type=“journal“ pubid=“Weikum01“>
<author>Gerhard Weikum</author>
<text>In the Web of 2010, XML <cite cid=„12“/>...</text>
<citation cid=„12“ ref=„XML98“/>
<citation cid=„15“>...</citation>
</publication>
<publication type=“inproceedings“ pubid=“XML98“>
<text>XML, the extended Markup Language, ...</text>
</publication>
</publications>
27
Attribute Examples
<ATTLIST publication type (journal|inproceedings) #REQUIRED
pubid ID #REQUIRED>
<ATTLIST cite cid IDREF #REQUIRED>
<ATTLIST citation ref IDREF #IMPLIED
cid ID #REQUIRED>
<publications>
<publication type=“journal“ pubid=“Weikum01“>
<author>Gerhard Weikum</author>
<text>In the Web of 2010, XML <cite cid=„12“/>...</text>
<citation cid=„12“ ref=„XML98“/>
<citation cid=„15“>...</citation>
</publication>
<publication type=“inproceedings“ pubid=“XML98“>
<text>XML, the extended Markup Language, ...</text>
</publication>
</publications>
28
Linking DTD and XML Docs
• Document Type Declaration in the XML document:
<!DOCTYPE article SYSTEM “http://www-dbs/article.dtd“>
keywords Root element URI for the DTD
29
Linking DTD and XML Docs
• Internal DTD:
<?xml version=“1.0“?>
<!DOCTYPE article [
<!ELEMENT article (title,author+,text)>
...
<!ELEMENT index (#PCDATA)>
]>
<article>
...
</article>
• Both ways can be mixed, internal DTD overwrites
external entity information:
<!DOCTYPE article SYSTEM „article.dtd“ [
<!ENTITY % pub_content (title+,author*,text)
]>
Internal & External DTD
• <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE note SYSTEM "Note.dtd">
• Note.dtd
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
30
• <?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend</body>
</note>
31
XSD-Schema
• Syntax
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="x" type="y"/>
<xs:attribute name="x" type="y"/>
Example
Simple Type
<xs:element name="phone_number" type="xs:int”/>
32
Complex Type
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name=“Address">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="company" type="xs:string" />
<xs:element name="phone" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
33
Global Type
<xs:element name="AddressType">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="company" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
34
Loading XML DOC
<script type=“text/javascript” language=“javascript”>
Fn fnname()
{
var xmldoc;
xmldoc=new ActiveXobject(“Microsoft.XMLDOM”)
xmldoc.load(“src”)
noderootelement=xmldoc.element;
nodeelement=nodeelementname.firstchild;
nodeelement=nodeelement.nextsibiling
………………………………………………..}
Example address.xml
<?xml version="1.0"?>
<contact-info>
<name>Tanmay Patil</name>
<company>TutorialsPoint</company>
<phone>(011) 123-4567</phone>
</contact-info>
35
<!DOCTYPE html> <html> <body> <h1>TutorialsPoint DOM example </h1> <div>
<b>Name:</b> <span id="name"></span><br> <b>Company:</b> <span
id="company"></span><br> <b>Phone:</b> <span id="phone"></span> </div>
<script> if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else
{// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} xmlhttp.open("GET","/xml/address.xml",false);
xmlhttp.send(); xmlDoc=xmlhttp.responseXML;
document.getElementById("name").innerHTML=
xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
document.getElementById("company").innerHTML=
xmlDoc.getElementsByTagName("company")[0].childNodes[0].nodeValue;
document.getElementById("phone").innerHTML=
xmlDoc.getElementsByTagName("phone")[0].childNodes[0].nodeValue;
</script> </body> </html>
36
XML - Namespaces
<?xml version="1.0" encoding="UTF-8"?>
<cont: contactxmlns: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>
37
Xml with CSS
CATALOG.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/css" href=“CATALOG.css"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR> </CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR> </CD> </CATALOG>
38
CATALOG.css
CATALOG { background-color: #ffffff; width: 100%; }
CD { display: block; margin-bottom: 30pt; margin-left: 0; }
TITLE { display: block; color: #ff0000; font-size: 20pt; }
ARTIST { display: block; color: #0000ff; font-size: 20pt; }
COUNTRY, PRICE, YEAR, COMPANY { display: block; color: #000000; margin-left: 20pt; }
39
Xml file
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with
plenty of real maple syrup</description>
<calories>650</calories>
</food>
</ breakfast_menu>
40
Xml with xslt
• <?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="breakfast_menu/food">
<div style="background-color:teal;color:white;padding:4px">
<span style="font-weight:bold"> <xsl:value-of select="name"/> - </span>
<xsl:value-of select="price"/>
</div>
<div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
<p>
<xsl:value-of select="description"/>
<span style="font-style:italic"> (<xsl:value-of select="calories"/> calories per
serving)</span>
</p>
</div>
</xsl:for-each>
</body>
</html>
41
Xpath
/bookstore/book[1]
/bookstore/book[last()]
/bookstore/book[last()-1]
/bookstore/book[position()<3]
//title[@lang]
//title[@lang='en‘]
/bookstore/book[price>35.00]
/bookstore/book[price>35.00]/title
42
Xml Link
XLink Syntax
<?xml version="1.0" encoding="UTF-8"?>
<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
<homepage xlink:type="simple" xlink:href="http://www.w3sch
ools.com">Visit W3Schools</homepage>
<homepage xlink:type="simple" xlink:href="http://www.w3.org
">Visit W3C</homepage>
</homepages>
Specifications
•xlink:actuate
•xlink:href
•xlink:show
•xlink:type
43
example
• <?xml version="1.0" encoding="UTF-8"?>
<bookstore xmlns:xlink="http://www.w3.org/1999/xlink">
<book title="Harry Potter">
<description
xlink:type="simple"
xlink:href="/images/HPotter.gif"
xlink:show="new">
As his fifth year at Hogwarts School of Witchcraft and
Wizardry approaches, 15-year-old Harry Potter is.......
</description>
</book>
• </bookstore>
44
Xml with ids
• <?xml version="1.0" encoding="UTF-8"?>
<dogbreeds>
<dog breed="Rottweiler" id="Rottweiler">
<picture url="http://dog.com/rottweiler.gif" />
<history>The Rottweiler's ancestors were probably Roman
drover dogs.....</history>
<temperament>Confident, bold, alert and imposing, the Rottweiler
is a popular choice for its ability to protect....</temperament>
</dog>
• </dogbreeds>
45
Xml with xpointer
• <?xml version="1.0" encoding="UTF-8"?>
<mydogs xmlns:xlink="http://www.w3.org/1999/xlink">
<mydog>
<description>
Anton is my favorite dog. He has won a lot of.....
</description>
<fact xlink:type="simple" xlink:href="http://dog.com/dogbreeds.xml#Rottweiler">
Fact about Rottweiler
</fact>
</mydog>
• </mydogs>
46
Xml into the server
• <%
'Load XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("simple.xml"))
'Load XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("simple.xsl"))
'Transform file
Response.Write(xml.transformNode(xsl))
%>
47

Weitere ähnliche Inhalte

Was ist angesagt?

oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaCPD INDIA
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XMLyht4ever
 
Cascading Style Sheets(CSS)
Cascading Style Sheets(CSS)Cascading Style Sheets(CSS)
Cascading Style Sheets(CSS)Reshmi Rajan
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
HTML5 audio & video
HTML5 audio & videoHTML5 audio & video
HTML5 audio & videoHamza Zahid
 
CSS - Text Properties
CSS - Text PropertiesCSS - Text Properties
CSS - Text Propertieshstryk
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate pptAneega
 
Html images syntax
Html images syntaxHtml images syntax
Html images syntaxJayjZens
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The BasicsJeff Fox
 
Html table tags
Html table tagsHtml table tags
Html table tagseShikshak
 
Networking concepts
Networking conceptsNetworking concepts
Networking conceptsseemadav1
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSSAmit Tyagi
 

Was ist angesagt? (20)

oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Generics
GenericsGenerics
Generics
 
Cascading Style Sheets(CSS)
Cascading Style Sheets(CSS)Cascading Style Sheets(CSS)
Cascading Style Sheets(CSS)
 
Oops in Java
Oops in JavaOops in Java
Oops in Java
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
How to learn HTML in 10 Days
How to learn HTML in 10 DaysHow to learn HTML in 10 Days
How to learn HTML in 10 Days
 
HTML5 audio & video
HTML5 audio & videoHTML5 audio & video
HTML5 audio & video
 
CSS - Text Properties
CSS - Text PropertiesCSS - Text Properties
CSS - Text Properties
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Html images syntax
Html images syntaxHtml images syntax
Html images syntax
 
Css lecture notes
Css lecture notesCss lecture notes
Css lecture notes
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Html table tags
Html table tagsHtml table tags
Html table tags
 
XSLT
XSLTXSLT
XSLT
 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
 
Networking concepts
Networking conceptsNetworking concepts
Networking concepts
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 

Ähnlich wie Xml Lecture Notes (20)

Xml
XmlXml
Xml
 
XML for beginners
XML for beginnersXML for beginners
XML for beginners
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
23xml
23xml23xml
23xml
 
Xml
XmlXml
Xml
 
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5   XMLM.FLORENCE DAYANA WEB DESIGN -Unit 5   XML
M.FLORENCE DAYANA WEB DESIGN -Unit 5 XML
 
Unit 5 xml (1)
Unit 5   xml (1)Unit 5   xml (1)
Unit 5 xml (1)
 
Decoding and developing the online finding aid
Decoding and developing the online finding aidDecoding and developing the online finding aid
Decoding and developing the online finding aid
 
Xml and DTD's
Xml and DTD'sXml and DTD's
Xml and DTD's
 
01 xml document structure
01 xml document structure01 xml document structure
01 xml document structure
 
XML-Unit 1.ppt
XML-Unit 1.pptXML-Unit 1.ppt
XML-Unit 1.ppt
 
Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
 
Xml 1
Xml 1Xml 1
Xml 1
 
Wisneski TeI workshop 2009-2010
Wisneski TeI workshop 2009-2010Wisneski TeI workshop 2009-2010
Wisneski TeI workshop 2009-2010
 
Xml Case Learns 2008
Xml Case Learns 2008Xml Case Learns 2008
Xml Case Learns 2008
 
Markup For Dummies (Russ Ward)
Markup For Dummies (Russ Ward)Markup For Dummies (Russ Ward)
Markup For Dummies (Russ Ward)
 
Xml
XmlXml
Xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Xml session
Xml sessionXml session
Xml session
 
chapter 4 web authoring unit 4 xml.pptx
chapter 4 web authoring  unit 4 xml.pptxchapter 4 web authoring  unit 4 xml.pptx
chapter 4 web authoring unit 4 xml.pptx
 

Mehr von Santhiya Grace

Mehr von Santhiya Grace (9)

Xml p5 Lecture Notes
Xml p5 Lecture NotesXml p5 Lecture Notes
Xml p5 Lecture Notes
 
Xml p4 Lecture Notes
Xml p4  Lecture NotesXml p4  Lecture Notes
Xml p4 Lecture Notes
 
Xml p3 -Lecture Notes
Xml p3 -Lecture NotesXml p3 -Lecture Notes
Xml p3 -Lecture Notes
 
Xml p2 Lecture Notes
Xml p2 Lecture NotesXml p2 Lecture Notes
Xml p2 Lecture Notes
 
Php Lecture Notes
Php Lecture NotesPhp Lecture Notes
Php Lecture Notes
 
Ajax Lecture Notes
Ajax Lecture NotesAjax Lecture Notes
Ajax Lecture Notes
 
Events Lecture Notes
Events Lecture NotesEvents Lecture Notes
Events Lecture Notes
 
Software Quality Assurance
Software Quality AssuranceSoftware Quality Assurance
Software Quality Assurance
 
Software Quality Assurance class 1
Software Quality Assurance  class 1Software Quality Assurance  class 1
Software Quality Assurance class 1
 

Kürzlich hochgeladen

Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 

Kürzlich hochgeladen (20)

Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 

Xml Lecture Notes

  • 2. 2 XML is not… • A replacement for HTML (but HTML can be generated from XML) • A presentation format (but XML can be converted into one) • A programming language (but it can be used with almost any language) • A network transfer protocol (but XML may be transferred over a network) • A database (but XML may be stored into a database)
  • 3. 3 XML by Example <article> <author>Gerhard Weikum</author> <title>The Web in 10 Years</title> </article> • Easy to understand for human users • Very expressive (semantics along with the data) • Well structured, easy to read and write from programs This looks nice, but…
  • 4. 4 XML by Example <t108> <x87>Gerhard Weikum</x87> <g10>The Web in 10 Years</g10> </t108> • Hard to understand for human users • Not expressive (no semantics along with the data) • Well structured, easy to read and write from programs … this is XML, too:
  • 5. 5 XML by Example <data> ch37fhgks73j5mv9d63h5mgfkds8d984lgnsmcns983 </data> • Impossible to understand for human users • Not expressive (no semantics along with the data) • Unstructured, read and write only with special programs … and what about this XML document: The actual benefit of using XML highly depends on the design of the application.
  • 6. 6 Possible Advantages of Using XML • Truly Portable Data • Easily readable by human users • Very expressive (semantics near data) • Very flexible and customizable (no finite tag set) • Easy to use from programs (libs available) • Easy to convert into other representations (XML transformation languages) • Many additional standards and tools • Widely used and supported
  • 7. 7 A Simple XML Document <article> <author>Gerhard Weikum</author> <title>The Web in Ten Years</title> <text> <abstract>In order to evolve...</abstract> <section number=“1” title=“Introduction”> The <index>Web</index> provides the universal... </section> </text> </article> Freely definable tags
  • 8. 8 Element Content of the Element (Subelements and/or Text) A Simple XML Document <article> <author>Gerhard Weikum</author> <title>The Web in Ten Years</title> <text> <abstract>In order to evolve...</abstract> <section number=“1” title=“Introduction”> The <index>Web</index> provides the universal... </section> </text> </article> End Tag Start Tag
  • 9. 9 A Simple XML Document <article> <author>Gerhard Weikum</author> <title>The Web in Ten Years</title> <text> <abstract>In order to evolve...</abstract> <section number=“1” title=“Introduction”> The <index>Web</index> provides the universal... </section> </text> </article> Attributes with name and value
  • 10. 10 Elements in XML Documents • (Freely definable) tags: article, title, author – with start tag: <article> etc. – and end tag: </article> etc. • Elements: <article> ... </article> • Elements have a name (article) and a content (...) • Elements may be nested. • Elements may be empty: <this_is_empty/> • Element content is typically parsed character data (PCDATA), i.e., strings with special characters, and/or nested elements (mixed content if both). • Each XML document has exactly one root element and forms a tree. • Elements with a common parent are ordered.
  • 11. 11 Elements vs. Attributes Elements may have attributes (in the start tag) that have a name and a value, e.g. <section number=“1“>. What is the difference between elements and attributes? • Only one attribute with a given name per element (but an arbitrary number of subelements) • Attributes have no structure, simply strings (while elements can have subelements) As a rule of thumb: • Content into elements • Metadata into attributes Example: <person born=“1912-06-23“ died=“1954-06-07“> Alan Turing</person> proved that…
  • 12. 12 XML Documents as Ordered Trees article author title text sectionabstract The index Web provides … title=“…“ number=“1“ In order … Gerhard Weikum The Web in 10 years
  • 13. 13 More on XML Syntax • <root>  <child>    <subchild>.....</subchild>  </child></root> • <?xml version="1.0" encoding="UTF-8"?> • XML Tags are Case Sensitive • XML Elements Must be Properly Nested • XML Attribute Values Must be Quoted • <!-- This is a comment --> • Some special characters must be escaped using entities: < →  &lt; & →  &amp; (will be converted back when reading the XML doc) • Some other characters may be escaped, too: > →  &gt; “ →  &quot; ‘ →  &apos;
  • 14. 14 Well-Formed XML Documents A well-formed document must adher to, among others, the  following rules: • Every start tag has a matching end tag. • Elements may nest, but must not overlap. • There must be exactly one root element. • Attribute values must be quoted. • An element may not have two attributes with the same  name. • Comments and processing instructions may not appear  inside tags. • No unescaped < or & signs may occur inside character  data.
  • 15. 15 Well-Formed XML Documents A well-formed document must adher to, among others, the  following rules: • Every start tag has a matching end tag. • Elements may nest, but must not overlap. • There must be exactly one root element. • Attribute values must be quoted. • An element may not have to attributes with the same  name. • Comments and processing instructions may not appear  inside tags. • No unescaped < or & signs may occur inside character  data. Only well-formed documents can be processed by XML parsers.
  • 16. 16 Namespace Syntax <dbs:book xmlns:dbs=“http://www-dbs/dbs“> Unique URI to identify the namespace Signal that namespace  definition happens Prefix as abbrevation of URI
  • 17. 17 Namespace Example <dbs:book xmlns:dbs=“http://www-dbs/dbs“> <dbs:description> ... </dbs:description> <dbs:text> <dbs:formula> <mathml:math xmlns:mathml=“http://www.w3.org/1998/Math/MathML“> ... </mathml:math> </dbs:formula> </dbs:text> </dbs:book>
  • 18. 18 Default Namespace • Default namespace may be set for an element and its  content (but not its attributes): <book xmlns=“http://www-dbs/dbs“> <description>...</description> <book> • Can be overridden in the elements by specifying the  namespace there (using prefix or default namespace)
  • 19. 19 3.1 Document Type Definitions Sometimes XML is too flexible: • Most Programs can only process a subset of all possible XML applications • For exchanging data, the format (i.e., elements, attributes and their semantics) must be fixed ⇒ Document Type Definitions (DTD) for establishing the vocabulary for one XML application (in  some sense comparable to schemas in databases) A document is valid with respect to a DTD if it conforms to the rules specified in that DTD. Most XML parsers can be configured to validate. <!DOCTYPE element DTD identifier  [ declaration1 declaration2 ........ ]>
  • 20. 20 DTD Example: Elements <!ELEMENT article (title,author+,text)> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT text (abstract,section*,literature?)> <!ELEMENT abstract (#PCDATA)> <!ELEMENT section (#PCDATA|index)+> <!ELEMENT literature (#PCDATA)> <!ELEMENT index (#PCDATA)> Content of the title element is parsed character data Content of the article element is a title element, followed by one or more author elements, followed by a text element Content of the text element may contain zero or more section elements in this position
  • 21. 21 Element Declarations in DTDs One element declaration for each element type: <!ELEMENT element_name content_specification> where content_specification can be • (#PCDATA)  parsed character data • (child)  one child element • (c1,…,cn) a sequence of child elements c1…cn • (c1|…|cn) one of the elements c1…cn For each component c, possible counts can be specified: – c exactly one such element – c+  one or more – c*  zero or more – c?  zero or one  Plus arbitrary combinations using parenthesis: <!ELEMENT f ((a|b)*,c+,(d|e))*>
  • 22. 22 More on Element Declarations • Elements with mixed content: <!ELEMENT text (#PCDATA|index|cite|glossary)*> • Elements with empty content: <!ELEMENT image EMPTY> • Elements with arbitrary content (this is nothing for  production-level DTDs): <!ELEMENT thesis ANY>
  • 23. 23 Attribute Declarations in DTDs Attributes are declared per element: <!ATTLIST section number CDATA #REQUIRED title CDATA #REQUIRED> declares two required attributes for element section. element name attribute name attribute type attribute default
  • 24. 24 Attribute Declarations in DTDs Attributes are declared per element: <!ATTLIST section number CDATA #REQUIRED title CDATA #REQUIRED> declares two required attributes for element section. Possible attribute defaults: • #REQUIRED is required in each element instance • #IMPLIED is optional • #FIXED default always has this default value • default has this default value if the attribute is omitted from the element instance
  • 25. 25 Attribute Types in DTDs • CDATA string data • (A1|…|An) enumeration of all possible values of the attribute (each is XML name) • ID unique XML name to identify the element • IDREF refers to ID attribute of some other element („intra-document link“) • IDREFS list of IDREF, separated by white space • plus some more
  • 26. 26 Attribute Examples <ATTLIST publication type (journal|inproceedings) #REQUIRED pubid ID #REQUIRED> <ATTLIST cite cid IDREF #REQUIRED> <ATTLIST citation ref IDREF #IMPLIED cid ID #REQUIRED> <publications> <publication type=“journal“ pubid=“Weikum01“> <author>Gerhard Weikum</author> <text>In the Web of 2010, XML <cite cid=„12“/>...</text> <citation cid=„12“ ref=„XML98“/> <citation cid=„15“>...</citation> </publication> <publication type=“inproceedings“ pubid=“XML98“> <text>XML, the extended Markup Language, ...</text> </publication> </publications>
  • 27. 27 Attribute Examples <ATTLIST publication type (journal|inproceedings) #REQUIRED pubid ID #REQUIRED> <ATTLIST cite cid IDREF #REQUIRED> <ATTLIST citation ref IDREF #IMPLIED cid ID #REQUIRED> <publications> <publication type=“journal“ pubid=“Weikum01“> <author>Gerhard Weikum</author> <text>In the Web of 2010, XML <cite cid=„12“/>...</text> <citation cid=„12“ ref=„XML98“/> <citation cid=„15“>...</citation> </publication> <publication type=“inproceedings“ pubid=“XML98“> <text>XML, the extended Markup Language, ...</text> </publication> </publications>
  • 28. 28 Linking DTD and XML Docs • Document Type Declaration in the XML document: <!DOCTYPE article SYSTEM “http://www-dbs/article.dtd“> keywords Root element URI for the DTD
  • 29. 29 Linking DTD and XML Docs • Internal DTD: <?xml version=“1.0“?> <!DOCTYPE article [ <!ELEMENT article (title,author+,text)> ... <!ELEMENT index (#PCDATA)> ]> <article> ... </article> • Both ways can be mixed, internal DTD overwrites external entity information: <!DOCTYPE article SYSTEM „article.dtd“ [ <!ENTITY % pub_content (title+,author*,text) ]>
  • 30. Internal & External DTD • <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE note SYSTEM "Note.dtd"> • Note.dtd <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> 30
  • 31. • <?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note> 31
  • 32. XSD-Schema • Syntax <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="x" type="y"/> <xs:attribute name="x" type="y"/> Example Simple Type <xs:element name="phone_number" type="xs:int”/> 32
  • 33. Complex Type <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name=“Address"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string" /> <xs:element name="company" type="xs:string" /> <xs:element name="phone" type="xs:int" /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> 33
  • 34. Global Type <xs:element name="AddressType"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string" /> <xs:element name="company" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> 34
  • 35. Loading XML DOC <script type=“text/javascript” language=“javascript”> Fn fnname() { var xmldoc; xmldoc=new ActiveXobject(“Microsoft.XMLDOM”) xmldoc.load(“src”) noderootelement=xmldoc.element; nodeelement=nodeelementname.firstchild; nodeelement=nodeelement.nextsibiling ………………………………………………..} Example address.xml <?xml version="1.0"?> <contact-info> <name>Tanmay Patil</name> <company>TutorialsPoint</company> <phone>(011) 123-4567</phone> </contact-info> 35
  • 36. <!DOCTYPE html> <html> <body> <h1>TutorialsPoint DOM example </h1> <div> <b>Name:</b> <span id="name"></span><br> <b>Company:</b> <span id="company"></span><br> <b>Phone:</b> <span id="phone"></span> </div> <script> if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","/xml/address.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.getElementById("name").innerHTML= xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue; document.getElementById("company").innerHTML= xmlDoc.getElementsByTagName("company")[0].childNodes[0].nodeValue; document.getElementById("phone").innerHTML= xmlDoc.getElementsByTagName("phone")[0].childNodes[0].nodeValue; </script> </body> </html> 36
  • 37. XML - Namespaces <?xml version="1.0" encoding="UTF-8"?> <cont: contactxmlns: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> 37
  • 38. Xml with CSS CATALOG.xml <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml-stylesheet type="text/css" href=“CATALOG.css"?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> </CATALOG> 38
  • 39. CATALOG.css CATALOG { background-color: #ffffff; width: 100%; } CD { display: block; margin-bottom: 30pt; margin-left: 0; } TITLE { display: block; color: #ff0000; font-size: 20pt; } ARTIST { display: block; color: #0000ff; font-size: 20pt; } COUNTRY, PRICE, YEAR, COMPANY { display: block; color: #000000; margin-left: 20pt; } 39
  • 40. Xml file <?xml version="1.0" encoding="UTF-8"?> <breakfast_menu> <food> <name>Belgian Waffles</name> <price>$5.95</price> <description>Two of our famous Belgian Waffles with plenty of real maple syrup</description> <calories>650</calories> </food> </ breakfast_menu> 40
  • 41. Xml with xslt • <?xml version="1.0" encoding="UTF-8"?> <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE"> <xsl:for-each select="breakfast_menu/food"> <div style="background-color:teal;color:white;padding:4px"> <span style="font-weight:bold"> <xsl:value-of select="name"/> - </span> <xsl:value-of select="price"/> </div> <div style="margin-left:20px;margin-bottom:1em;font-size:10pt"> <p> <xsl:value-of select="description"/> <span style="font-style:italic"> (<xsl:value-of select="calories"/> calories per serving)</span> </p> </div> </xsl:for-each> </body> </html> 41
  • 43. Xml Link XLink Syntax <?xml version="1.0" encoding="UTF-8"?> <homepages xmlns:xlink="http://www.w3.org/1999/xlink"> <homepage xlink:type="simple" xlink:href="http://www.w3sch ools.com">Visit W3Schools</homepage> <homepage xlink:type="simple" xlink:href="http://www.w3.org ">Visit W3C</homepage> </homepages> Specifications •xlink:actuate •xlink:href •xlink:show •xlink:type 43
  • 44. example • <?xml version="1.0" encoding="UTF-8"?> <bookstore xmlns:xlink="http://www.w3.org/1999/xlink"> <book title="Harry Potter"> <description xlink:type="simple" xlink:href="/images/HPotter.gif" xlink:show="new"> As his fifth year at Hogwarts School of Witchcraft and Wizardry approaches, 15-year-old Harry Potter is....... </description> </book> • </bookstore> 44
  • 45. Xml with ids • <?xml version="1.0" encoding="UTF-8"?> <dogbreeds> <dog breed="Rottweiler" id="Rottweiler"> <picture url="http://dog.com/rottweiler.gif" /> <history>The Rottweiler's ancestors were probably Roman drover dogs.....</history> <temperament>Confident, bold, alert and imposing, the Rottweiler is a popular choice for its ability to protect....</temperament> </dog> • </dogbreeds> 45
  • 46. Xml with xpointer • <?xml version="1.0" encoding="UTF-8"?> <mydogs xmlns:xlink="http://www.w3.org/1999/xlink"> <mydog> <description> Anton is my favorite dog. He has won a lot of..... </description> <fact xlink:type="simple" xlink:href="http://dog.com/dogbreeds.xml#Rottweiler"> Fact about Rottweiler </fact> </mydog> • </mydogs> 46
  • 47. Xml into the server • <% 'Load XML set xml = Server.CreateObject("Microsoft.XMLDOM") xml.async = false xml.load(Server.MapPath("simple.xml")) 'Load XSL set xsl = Server.CreateObject("Microsoft.XMLDOM") xsl.async = false xsl.load(Server.MapPath("simple.xsl")) 'Transform file Response.Write(xml.transformNode(xsl)) %> 47