Upload
wilfrid-jenkins
View
214
Download
2
Embed Size (px)
Citation preview
3
XML Namespaces
3 - 2
XML Namespaces
Order No. 13-453
Dear Dr. Smith,
we confirm your order of thebook
1 The XML HandbookISBN: 0130811521Price: USD 44.95
and ask you kindly to transfer
the amount ...
Best regards
"Title"
3 - 3
<order> <title>XML Handbook</title> <isbn>0130811521</isbn> <price currency="USD">44.95</price> <title>Dr.</title> <forename>Paul</forename> <lastname>Smith</lastname> <address> ... </address> <creditcard cardtype="Visa"> ... </creditcard> <phone> ... </phone> <email> ... </email></order>
Collision
<book> <title>XML Handbook</title> <authors> <author>Goldfarb</author> <author>Prescod</author> </authors> <publisher>Prentice Hall</publisher> <pages>655</pages> <isbn>0130811521</isbn> <price currency="USD">44.95</price></book>
<customer> <title>Dr.</title> <forename>Paul</forename> <lastname>Smith</lastname> <address> ... </address> <creditcard cardtype="Visa"> ... </creditcard> <phone> ... </phone> <email> ... </email> </customer>
3 - 4
Namespace Declaration
<?xml version="1.0"?><order xmlns:bk="http://www.net-standard.com/namespaces/books" xmlns:cust="http://www.net-standard.com/namespaces/customer" xmlns:fin="http://www.net-standard.com/namespaces/financial">
<bk:title>XML Handbook</bk:title> <bk:isbn>0130811521</bk:isbn> <bk:price fin:currency="USD">44.95</bk:price> <cust:title>Dr.</cust:title> <cust:forename>Paul</cust:forename> <cust:lastname>Smith</cust:lastname> <cust:address> ... </cust:address> <cust:creditcard fin:cardtype="Visa">... </cust:creditcard> <cust:phone> ... </cust:phone> <cust:email> ... </cust:email></order>
3 - 5
Default Namespace
<?xml version="1.0"?><order xmlns="http://www.net-standard.com/namespaces/order" xmlns:bk="http://www.net-standard.com/namespaces/books" xmlns:cust="http://www.net-standard.com/namespaces/customer">
<order-date>20.10.1999</order-date> <order-number>55544-3</order-number> <bk:book> <bk:title>XML Handbook</bk:title> <bk:isbn>0130811521</bk:isbn> </bk:book> <cust:customer> <cust:title>Dr.</cust:title> <cust:forename>Paul</cust:forename> <cust:lastname>Smith</cust:lastname> <cust:address> ... </cust:address> <cust:phone> ... </cust:phone> </cust:customer></order>
3 - 6
Override Default Namespaces
<order xmlns="http://www.net-standard.com/namespaces/order" xmlns:ord="http://www.net-standard.com/namespaces/order" xmlns:bk="http://www.net-standard.com/namespaces/books" xmlns:cust="http://www.net-standard.com/namespaces/customer"> <ord:description xmlns="http://www.w3.org/1999/xhtml"> <html> <head><title>Order</title></head> <body> <h1>Book order</h1> <p> The order of the following books is made by phone...</p> </body> </html> </ord:description> <order-date>20.10.1999</order-date> <order-number>55544-3</order-number> <bk:book> <bk:title>XML Handbook</bk:title>… </bk:book>…</order>
3 - 7
Empty Namespace<?xml version="1.0"?><order xmlns="http://www.net-standard.com/namespaces/order" xmlns:bk="http://www.net-standard.com/namespaces/books" xmlns:cust="http://www.net-standard.com/namespaces/customer"> <order-date>20.10.1999</order-date> <order-number>55544-3</order-number> <bk:book> <bk:isbn>0130811521</bk:isbn> </bk:book> <cust:customer> <comment xmlns=" ">This comment belongs to no namespace</comment> <cust:forename>Paul</cust:forename> <cust:lastname>Smith</cust:lastname> <cust:address> ... </cust:address> <cust:phone> ... </cust:phone> <cust:email> ... </cust:email> </cust:customer></order>
3 - 8
Namespaces and Attributes
These attributes donot belong to a namespace
These attributes donot belong to a namespace
<?xml version="1.0"?><order xmlns="http://www.net-standard.com/namespaces/order" xmlns:bk="http://www.net-standard.com/namespaces/books" xmlns:cust="http://www.net-standard.com/namespaces/customer" xmlns:fin="http://www.net-standard.com/namespaces/financial" order-number="55544-3"> <order-date>20.10.1999</order-date> <bk:book> <bk:title>XML Handbook</bk:title> <bk:isbn>0130811521</bk:isbn> </bk:book> <cust:customer> <cust:title>Dr.</cust:title> <cust:forename>Paul</cust:forename> <cust:lastname>Smith</cust:lastname> <cust:address> ... </cust:address> <fin:creditcard cardtype="Visa"> ... </fin:creditcard> </cust:customer></order>
3 - 9
Namespaces and Attributes
<?xml version="1.0"?><order xmlns="http://www.net-standard.com/namespaces/order" xmlns:ord="http://www.net-standard.com/namespaces/order" xmlns:bk="http://www.net-standard.com/namespaces/books" xmlns:cust="http://www.net-standard.com/namespaces/customer" xmlns:fin="http://www.net-standard.com/namespaces/financial" ord:order-number="55544-3"> <order-date>20.10.1999</order-date> <bk:book> <bk:title>XML Handbook</bk:title> <bk:isbn>0130811521</bk:isbn> </bk:book> <cust:customer> <cust:title>Dr.</cust:title> <cust:forename>Paul</cust:forename> <cust:lastname>Smith</cust:lastname> <cust:address> ... </cust:address> <fin:creditcard fin:cardtype="Visa"> ... </fin:creditcard> </cust:customer></order>
3 - 10
Summary
XML namespaces identify the semantics of an element or attribute, especially in cases where documents have elements with the same names but different meaning. This is the case, for example, where standardized DTDs are used.
XML namespaces are increasingly used in XML applications to ensure the consistency of the meaning of names in documents and applications.