Default name space

Source: Internet
Author: User
Tags cdata contains end return xmlns xsl
Name space


If you define a default namespace for an element, we do not have to use prefixes in all child elements. Its syntax is this:

< element xmlns= "namespace" >

This XML document carries information in a table:

< table xmlns= "http://www.w3.org/TR/html4/" >
< tr>
< td>apples< td>
< td>bananas< td>
< tr>
</table>

This XML document carries information about a piece of furniture:

< table xmlns= "Http://www.w3schools.com/furniture" >
< Name>african Coffee table</name>
< width>80</width>
< length>120</length>
</table>


B> use namespaces in practice

When you start using XSL, you'll soon see the use of namespaces in the real world. The XSL format table is used to convert XML documents into other formats, such as HTML. A closer look at the following XSL document shows that most of the markup is HTML markup. Tags that are not html have a prefix XSL that is identified by the namespace "http://www.w3.org/TR/xsl":

< XML version= ' 1.0 '?>
< Xsl:stylesheet xmlns:xsl= "http://www.w3.org/TR/xsl" >
< xsl:template match= "/" >
< html>
< body>
< table border= "2" bgcolor= "Yellow" >
< tr>
< th>title</th>
< th>artist</th>
</tr>
< Xsl:for-each select= "CATALOG/CD" >
< tr>
< td>< xsl:value-of select= "TITLE"/></td>
< td>< xsl:value-of select= "ARTIST"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</xsl:template>
</xsl:stylesheet>

XML PCDATA and CDATA

The decomposable character data (PCDATA) is the text decomposed by the factorization. Character data (CDATA) is text that is not decomposed by the factorization.



B>pcdata

The XML factorization treats all text as a decomposable character (PCDATA). When an XML element is decomposed, the text between the XML tags is also decomposed:

< Message>this text is also parsed</message>

The factorization does this because XML elements can contain other elements, as in this example, the < name> element contains the other two elements (first and last):

< name>< first>bill</first>< last>gates</last></name>

The factorization will break it down into child elements, like this:

< name>
< first>bill</first>
< last>gates</last>
</name>



B>escape characters

Illegal XML characters must be replaced with entity references. If you place a character in an XML element, such as "<," it generates an error because the factorization interprets it as the beginning of a new element. You can't write like this:

< Message>if Salary < 1000 then</message>

To avoid this, you have to use an entity reference instead of the "<" character, like this:

< Message>if Salary < 1000 then</message>

There are 5 predefined entity references in XML:

< < less than
> > Greater than
& & & Symbols
' Ellipsis
"" Quote

Entity references usually start with a "&" symbol and end with a ";" Symbol. Note: Strictly speaking in XML, only the "<" and "&" symbols are illegal. ellipses, quotes, and greater-than numbers are all legal, but it is best to replace them.



B>cdata

The factorization ignores all content within the CDATA region. If your text contains many "<" or "&" Symbols---program encoding is usually---then the XML element can be defined as a CDATA region. A CDATA area with "<!" Start with [cdata[], End With "]]>":

< script>
<! [cdata[
function Matchwo (a,b)
{
if (A < b && a < 0) then
{
Return 1
}
Else
{
return 0
}
}
]]>
</script>

In the previous example, the entire contents of the CDATA area were ignored by the factorization.



Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.