Interview Questions

How do I use prefixes to refer to element type and attribute names in an XML namespace?

XML Interview Questions and Answers


(Continued from previous question...)

74. How do I use prefixes to refer to element type and attribute names in an XML namespace?

Make sure you have declared the prefix and that it is still in scope . All you need to do then is prefix the local name of an element type or attribute with the prefix and a colon. The result is a qualified name, which the application parses to determine what XML namespace the local name belongs to.
For example, suppose you have associated the serv prefix with the http://www.our.com/ito/servers namespace and that the declaration is still in scope. In the following, serv:Address refers to the Address name in the http://www.our.com/ito/servers namespace. (Note that the prefix is used on both the start and end tags.)
<!-- serv refers to the http://www.our.com/ito/servers namespace. -->
<serv:Address>127.66.67.8</serv:Address>

Now suppose you have associated the xslt prefix with the http://www.w3.org/1999/XSL/Transform namespace. In the following, xslt:version refers to the version name in the http://www.w3.org/1999/XSL/Transform namespace:
<!-- xslt refers to the http://www.w3.org/1999/XSL/Transform namespace. -->
<html xslt:version="1.0">

(Continued on next question...)

Other Interview Questions