Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML Name spaces. Different people may invent similar tag names Here is an XML element describing a piece of furniture: table99 dining table 80 180 Here.

Similar presentations


Presentation on theme: "XML Name spaces. Different people may invent similar tag names Here is an XML element describing a piece of furniture: table99 dining table 80 180 Here."— Presentation transcript:

1 XML Name spaces

2 Different people may invent similar tag names Here is an XML element describing a piece of furniture: table99 dining table 80 180 Here is an XML element describing a collection of data: Bertie Ahern male Mary Harney female

3 Distinguishing tags with similar names Sometimes an application will involve multiple documents, each containing tags that have the same names but different meanings We can distinguish between similar tag names by using prefixes

4 Distinguishing tags with similar names (contd.) The XML element describing a piece of furniture: table99 dining table 80 180 The XML element describing a collection of data: Bertie Ahern male Mary Harney female

5 Distinguishing tags with similar names (contd.) But two different software engineers might even still choose similar prefixes! Extract from one application: table99 dining table 80 180 Extract from another application: 199 second-hand

6 Distinguishing tags with similar names (contd.) We avoid ambiguity by associating each prefix with something that must be unique –a Universal Resource Identifier The association between a prefix and a URI is made using a special XML attribute –the XML Namespace (xmlns) Attribute Format of the xmlns attribute: xmlns:prefix="URI” Example usages: By the way: never invent your own tag/attribute names starting with “xml…” – these are reserved for W3C usage

7 Distinguishing tags with similar names (contd.) When a namespace is defined in the start tag of an element, all child elements with the same prefix are associated with the same namespace Example table99 dining table 80 180 In this case, all the furniture prefixes are associated with the http://abc.com URI

8 Some more examples A different furniture example: 199 second-hand A personnel data example Bertie Ahern male Mary Harney female

9 Default Namespaces We can reduce the need for prefixes if we define a default namespace for an element All tag names in descendant elements are then understood as implicitly having the same namespace as that for the ancestor element The format for a default namespace usage is … Example usage: 199 second-hand is equivalent to: 199 second-hand

10 Example usage of XML namespaces A frequent usage of namespaces is in XSL stylesheets There is an example on the next slide The XSL stylesheet transforms a particular form of XML document into XHTML Thus many of the tags in the stylesheet are XHTML tags But many tags are are XSL tags –they are identified as such by having the xsl prefix –and the semantics of the xsl prefix are defined by associating it with a W3C URI

11 <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform” version="1.0"> Data Name Sex male female

12 An XSL application where there would have been tagname clashes Consider the following XML fragment: table99 dining table 80 180 Suppose we wanted to use XSL to transform elements like this into elements like this table99 dining table 80 180 That is, we are replacing an application-specific element having the tagname type with one having the tagname template

13 An XSL application with potential tagname clash (contd.) Our XSL stylesheet would have two kinds of template element –one from the XSL language –another from the application-specific furniture language We would use the xsl prefix to distinguish one of these from the other Here is an extract from the relevant XML stylesheet:......


Download ppt "XML Name spaces. Different people may invent similar tag names Here is an XML element describing a piece of furniture: table99 dining table 80 180 Here."

Similar presentations


Ads by Google