1 / 11

Resolving Name Collisions in Compound XML Documents with Namespaces

Name collision in XML occurs when elements from different vocabularies share the same name, complicating document validation. This issue can be circumvented by utilizing namespaces, which provide a unique context for element and attribute names. By declaring a namespace using the `xmlns` attribute and associating elements with a prefix, you can avoid name collisions. This guide explains how to declare namespaces, identify elements within them, and effectively combine standard vocabularies such as XHTML and MathML in your XML documents, ensuring well-formed and valid data structures.

hea
Télécharger la présentation

Resolving Name Collisions in Compound XML Documents with Namespaces

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Compound Documents: Combining XML Vocabularies

  2. Problems with Name Collision Name collision occurs when elements from different XML vocabularies use the same name within a compound document Name collision is not a problem if you are not concerned with validation. The document content only needs to be well-formed. However, name collision will keep a document from being validated.

  3. Namespaces: The Way to Resolve Name Collisions A namespace is a defined collection of element and attribute names. Names that belong to the same namespace must be unique. Elements can share the same name if they reside in different namespaces. To apply namespaces to compound XML documents you must: Declare the namespace Identify which elements in the document belong in the namespace

  4. 1. Declaring a Namespace Declaring a namespace consists of adding the attribute xmlnsto an element as follows: xmlns:prefix=“URI” where URI is a Uniform Resource Identifier that assigns a unique name to the namespace, and prefix is a string of letters that associates each element or attribute in the document with the declared namespace. For example, <model xmlns:mod=“http://jacksonelect.com/models”> declares a namespace with the prefix modand the URI http://jacksonelect.com/models

  5. 2. Identifying Elements in the Namespace After you declare a namespace, you indicate which elements in the document belong to that namespace by attaching the namespace prefix: <prefix:element> content </prefix:element> Example: <mod:modelxmlns:mod="http://jacksonelect.com/models"> <mod:title>Laser4C (PR205)</mod:title> <mod:description>Printer</mod:description> <mod:type>color laser</mod:type> <mod:ordered>320</mod:ordered> <mod:parts list="chx201,fa100,eng005,450V4,tn01" /> </mod:model>

  6. Default Namespaces You can specify a default namespace by omitting the prefix in the namespace declaration. The element containing the namespace attribute and all of its child elements are assumed to be part of the default namespace. Example: <model xmlns="http://jacksonelect.com/models"> <title>Laser4C (PR205)</title> <description>Printer</description> <type>color laser</type> <ordered>320</ordered> <parts list="chx201,fa100,eng005,450V4,tn01" /> </model>

  7. Adding Namespace Prefixes to Attributes Attributes, like elements, can become qualified by adding the namespace prefix to the attribute name: <prefix:elementprefix:attribute="value">…</prefix:element> Example: <mod:modelxmlns:mod="http://jacksonelect.com/models" mod:id=“123”> This doesn’t happen very often except when an attribute in one namespace is used as an attribute in another namespace.

  8. Using Namespaces in a Style Sheet To declare a namespace in a style sheet, you add the following rule to the style sheet file: @namespace prefix “uri”;Example: @namespace mod “http://jacksonelect.com/models”; Selectors are associated with that namespace using the syntax: prefix|selector {attribute1:value1; …} Example: mod|title {width:150 px}

  9. Combining Standard Vocabularies Standard vocabularies may be combined within a single XML document. Some well-known XML vocabularies are:

  10. Example 1: Combining XHTML and MathML

  11. Example 2: Converting HTML to XHTML

More Related