Chose Language:
Author: Admin/Publisher |finished | checked

Namespaces en XML

Antes de continuar debemos de tener en claro que es un Namespace en XML a continuacion dejo la definición que he sacado desde TutorialPoint ya que creo que ellos han dado una buena definicion de estos.

A Namespace is a set of unique names. Namespace is a mechanisms by which element and attribute name can be assigned to a group. The Namespace is identified by URI(Uniform Resource Identifiers).

https://www.tutorialspoint.com/xml/xml_namespaces.htm

Es un set de nombres unicos. Es un mecanismo por el cual elementos y attributos pueden ser asignados a un grupo.

El Namespace es identificado por URI(Uniform Resource Identifiers)

¿Porque existen y porque su uso?

Los Namespaces existen por una razón simple, estos evitan el choque entre nombres los cuales generan conflicto entre los nombres.

Como los uso

Los namespaces los puede usar en cualquier elemento XML, y este es vigente hasta que el elemento no cierre.

Los namespaces son declarados como un attributo, tambien se pueden declarar multiples namespaces como atributos.

Los namespaces son declarados con xlmns solo o como comienzo de la declaracion de uno.

Default namespace

<html xmlns="{namespaceURI}"></html>

scoped namespace

<bookstable:table xmlns:bookstable="{namespaceURI}" >
  <bookstable:book>I Robot</bookstable:book>
  <bookstable:book>The World of Ice and fire</bookstable:book>
</bookstable:table>

Multiple namespaces

<bookstable:table xmlns:bookstable="{namespaceURI}" xmlns:authors="{othernamespaceURI}" >
  <bookstable:book>I Robot</bookstable:book>
  <authors:author>Asimov</authors:author>
  <bookstable:book>The World of Ice and fire</bookstable:book>
  <authors:author>George R.R Marting</authors:author>
</bookstable:table>

Recuerde que la URI puede estar conformada por cualquiera de los siguientes esquemas, asi pues no se preocupe ver una uri como la siguiente

<book xmlns:bookinfo="urn:isbn:9780553382563">
  <title>I Robot</title>
  <author>Isac Asimov</author>
</book>
  • about: Browser information
  • data: Embedded data
  • feed: Web feeds
  • file: Files
  • ftp: File Transfer Protocol
  • git: Version management with Git
  • http: Hypertext Transfer Protocol
  • https:Hypertext Transfer Protocol Secure
  • imap:Internet Message Access Protocol
  • mailto: Email addresses
  • news: Usenet newsgroups
  • pop: POP3
  • rsync: Data synchronization
  • sftp: SSH File Transfer Protocol
  • ssh: Secure shell
  • tel: Telephone numbers
  • urn: Uniform Resource Names

Referencias:

  • https://www.tutorialspoint.com/xml/xml_namespaces.htm
  • https://docs.microsoft.com/en-us/dotnet/standard/data/xml/managing-namespaces-in-an-xml-document
  • https://www.w3.org/TR/xml-names/
Category: otros
Something wrong? If you found an error or mistake in the content you can contact me on Twitter | @luisg2249_luis.
Last 4 post in same category