Upload
heidi
View
60
Download
2
Embed Size (px)
DESCRIPTION
Source: XML Bible 2 nd edition Elliotte Rusty Harold ISBN:0-7645-4760-7. The Complete Reference XML,Heather Williamson ISBN:0-07-212734-1 http://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-breakdown. XML Namespaces. by Navin Kumar Vedagiri. XML Namespaces. What is Namespace? - PowerPoint PPT Presentation
Citation preview
04/22/23 1
XML Namespaces
Source: XML Bible 2nd edition Elliotte Rusty Harold ISBN:0-7645-4760-7. The Complete Reference XML,Heather Williamson ISBN:0-07-212734-1 http://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-breakdown
by
Navin Kumar Vedagiri
04/22/23 2
XML Namespaces
What is Namespace?A namespace defines a new scope. Provide a way to avoid name collisions.
What is XML Namespace?To give multiple elements of same name within the same document
04/22/23 3
XML NamespaceXML allows users to create own markup language for their own projectsOne such example is MathML (Mathematics Markup Language)MathML is derivative of XMLMathML is used for displaying complex equationsXML documents containing MathML tags in one single document.This is where XML Namespaces comes in
04/22/23 4
Example<?xml version =“1.0”?><MATH>
<MI>a</MI><MI>a</MI><MI>a</MI><MI>a</MI><MI>a</MI>
</MATH>
<?xml version =“1.0”?><MATH_ASSIGNMENT>
<Question id =1><MATH>
<MI>a</MI><MI>a</MI><MI>a</MI><MI>a</MI><MI>a</MI>
<Instructions> A,B,C are sides of triangle……</Instruction></MATH></Question><Question id =2><MATH><Instructions> If a train…………………</Instruction></MATH></Question>
</MATH_ASSIGNMENT>
04/22/23 5
Conflicts In Name
Base element name in MathML is <MATH>If any of element name in XML code uses <MATH>Compiler should know which of the <MATH> object should be treated to MathML instructions and which should be interpreted as XML markupThis clearly shows Why we wanted Namespace and how scope of the name can be defined.
04/22/23 6
Using Namespaces In C++
Declaring Namespace in C++namespace direct { class Arrow
{ public: Arrow(int dir); void setDirection(int dir); private: int direction;
} // ...... other stuff } Using Namespace
using namespace direct; Direct.Arrow a = new Arrow();
04/22/23 7
Declaring Namespace In XML
Syntax for declaring a namespace<elementname xmlns:prefix =“namespaceurl”>
Namespace applied for MathML<MATH xmlns:nm=http://www.w3.org/TR/REC-MathML”>
04/22/23 8
Explanation Of Using Namespace
Prefix is used to identify that is associated with the element or attributeIn XSL, either element name or attribute name after namespace prefix can be used to identifyNamespace prefix is used with “xmlns” prefix to identify source of DTD used to identify universal attribute family
04/22/23 9
Example<?xml version=“1.0”?><MATH_ASSIGNMENT xmlns:mdoc=“http://www.catsback.com/MATH/”>
<mdoc:INSTRUCTIONS>Solve the following…..</mdoc:INSTRUCTIONS>
<mdoc:Question id=“1”><MATH xmlns:math=“http://www.w3.org/TR/REC-MathML”>
<math:MI>a</math:MI><math:MO>+</math:MO><math:MI>b</math:MI><math:MO>=</math:MO><math:MI>c</math:MI><mdoc:INSTRUCTIONS>
Where A,B,C……</mdoc:INSTRUCTIONS>
</MATH></mdoc:Question>
</MATH_ASSIGNMENT>
04/22/23 10
Explanation Of Using Namespace
<MATH_ASSIGNMENT> & <MATH> elements are using namespace declarations<MATH_ASSIGNMENT> refers to ww.catsback.com/MathNamespace for child elements need not be declared separatelyNamespace will be automatically applied to child elements and its attributes
04/22/23 11
URI – Uniform Resource Identifier
Abstraction of URLURL locates a resource, URI identifies a resourceURI doesn’t have to point at any particular fileURI defines a namespaceGroups and disambiguate element & attribute nameDocument need not exist at the URI specified
04/22/23 12
Qualified NameCombination of prefix and local part nameeg., <mdoc:Question> or <math:MI>Prefix is used as a placeholder for namespace nameIf the document scope extends past the current document then full URL should be usedExample serv:Address Address
04/22/23 13
Qualified Attribute
Applies prefix directly to name of the element or attribute within the markupOpening and closing tags must have prefix appliedIf qualifying within an element, apply prefix to name of the attribute
04/22/23 14
Default Namespaces
Applied to an element where it is declaredURL is left blank in “xmlns:” declarationChildren goes to default namespace without explicit declarationDo not apply to attributesProcessed faster than namespace prefixes
04/22/23 15
Example of Default Namespace
<?xml version=“1.0”?><MATH_ASSIGNMENT xmlns = “http://www.catsback.com/MATH/”>
<INSTRUCTIONS>Solve the following…..
</INSTRUCTIONS><Question id=“1”></Question>
</MATH_ASSIGNMENT>
04/22/23 16
Adding Namespace To DTDsIncorporating Namespace to DTD’s is beneficial and problematicSince xmlns:prefix declaration is treated as an attribute, must be defined within the DTDAll the element name must refer to their namespace
04/22/23 17
Adding Namespace To DTDsBook DTD<!ELEMENT BOOK (DIV+)><!ELEMENT DIV (HEAD, DIV*, PGPH*)><!ELEMENT HEAD (#PCDATA)>
Sonnet DTD<!ELEMENT SONNET (STANZA,STANZA,STANZA,REFRAIN)><!ELEMENT STANZA (LINE,LINE,LINE LINE)>
Play DTD
<!ELEMENT PLAY (ACTOR, WRITER)><!ELEMENT ACTOR(Fname, Lname, Age)><!ELEMENT WRITER(Name,Type)>
04/22/23 18
<b:BOOK xmlns:b=“book.dtd” xmlns:s =“sonnet.dtd” xmls:p=“play.dtd”><b:DIV>
<b:HEAD>…….</b:HEAD></b:DIV><b:DIV>
<b:HEAD>…..</b:HEAD><s:SONNET><s:STANZA id =“st1”><s:LINE>…….</s:LINE></s:STANZA><s:STANZA id =“st2”><s:LINE>…….</s:LINE></s:STANZA></s:SONNET><p:PLAY><p:Actor><p:Fname>…..</p:Fname></p:Actor></p:Play>
</b:DIV>
04/22/23 19
Namespace ScopingTo the element where it is specified and to all elements within the content of that elementIf overridden by another namespace declaration with the same NSAttName partMultiple Namespace scope
<?xml version="1.0"?><!-- both namespace prefixes are available throughout --><bk:book xmlns:bk='urn:loc.gov:books' xmlns:isbn='urn:ISBN:0-395-36341-6'> <bk:title>Cheaper by the Dozen</bk:title> <isbn:number>1568491379</isbn:number></bk:book>
04/22/23 20
Stylesheet - XML Namespace example<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="prompt">
<xsl:value-of select="greeting" />
</xsl:for-each>
</body>
</html> </xsl:template> </xsl:stylesheet>
04/22/23 21
ConstraintsEntity names, Processing Instruction TargetsOverriding default namespace
<A xmlns="http://www.foo.org/"> <B> <C xmlns="">
<D>abcd</D>
</C>
</B> </A>
04/22/23 22
Namespace scope for an elementExample 1: <A xmlns="http://www.foo.org/"> <B xmlns="http://www.bar.org/"> <C>abcd</C> </B> </A>
Example 2: <foo:A xmlns:foo="http://www.foo.org/"> <foo:B xmlns:foo="http://www.bar.org/"> <foo:C>abcd</foo:C> </foo:B> </foo:A>
04/22/23 23
Mapping Qualified Names
Example 1:<?xml version="1.0" ?>
<A xmlns="http://www.foo.org/" C="bar"> <B>abcd</B>
<A>
Example 2: <?xml version="1.0" ?> <A C="bar"> <B>abcd</B> <A>
04/22/23 24
Declaring at Root
<Department xmlns:addr="http://www.tu-darmstadt.de/ito/addresses" xmlns:serv="http://www.tu-darmstadt.de/ito/servers">
<Name>DVS1</Name>
<addr:Address>
<addr:Street>Wilhelminenstr. 7</addr:Street>
<addr:City>Darmstadt</addr:City>
</addr:Address>
<serv:Server>
<serv:Name>OurWebServer</serv:Name>
<serv:Address>123.45.67.8</serv:Address>
</serv:Server>
</Department>
04/22/23 25
Validation of XML-Namespace
Validity is a concept defined in XML XML namespaces are layered on top of XMLXML namespaces recommendation does not redefine validityxmlns attributes are treated as attributes, not XML namespace declarations.Qualified names are treated like other names.
04/22/23 26
SummaryNamespaces distinguis between elements and attributesIdentifies, which belong to XML and to other markup Declared by xmlns attributePrefix is attached to element and attributesNo prefix – Default namespaceDTD’s using namespaces should be designed carefully