XML Namespaces namespace

Source: Internet
Author: User
Tags xsl

ProgramI have written a lot, but I have been operating on XML more or less, but I am not fully familiar with some concepts of XML. Recently I have learned some basic knowledge about XML.

XML Namespaces namespace

Without looking at or using the namespace of XML, we still seldom know about it, and we do not know what it is.

The XML namespace is like the namespace of the. NET program. It can provide methods to avoid element naming conflicts.

Why is there a name conflict? Since the element names in XML are predefined, when two different documents use the same element names, a name conflict occurs.

This XML document carries the information in a table:

<Table> <tr> <TD> apples </TD> <TD> bananas </TD> </tr> </table>

This XML document carries information about the table (a piece of furniture ):

<Table> <Name> afrcan coffee table </Name> <width> 80 </width> <length> 120 </length> </table>

If the two XML documents are used together, because both documents contain <Table> elements with different content and definitions, naming conflicts will occur because their semantics is different, that is, we all want to name it table. Use a prefix to avoid name conflicts

This document contains information in a table:

<H: Table>  
 

This XML document carries information about a piece of furniture:

<F: Table> <F: Name> African coffee table </F: Name> <F: width> 80 </F: width> <F: length> 120 </F: length> </F: Table>

Now, the name conflict does not exist because both documents use different names to name their <Table> elements (

When we use XSL, we will see the namespace in use. XSL style sheets are used to convert XML documents to other formats, such as HTML.

<? XML version = "1.0" encoding = "ISO-8859-1"?> <XSL: stylesheetversion = "1.0"Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform"> <XSL: template match = "/">
</XSL: Template>

 

. The namespace for XML operations under. net. xmlnamespacemanager resolves the namespace of the Set, adds a namespace to the set, removes the namespace from the set, and provides range management for these namespaces, any prefix in the XPath expression uses the provided system. XML. xmlnamespacemanager is parsed. The following is a simple example of xpath.

Console. writeline (X. documentelement. namespaceuri );

Xmlnamespacemanager xmlnamespace = new xmlnamespacemanager (X. nametable );

Xmlnamespace. addnamespace ("XSL", "http://www.w3.org/1999/XSL/Transform ");

Console. writeline (X. selectsinglenode ("// XSL: Template", xmlnamespace). namespaceuri );

Console. writeline (X. selectsinglenode ("// XSL: Template/html", xmlnamespace). namespaceuri );

Console. Readline ();

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.