XML
- XML Básico
- Referencias
- Herramientas
- Metodología
- Ejemplos
- Otros Enlaces
Ruta: >Programación>XML
|
|
|
. | Elemento actual |
/ | La raíz del documento |
// | Todos los elementos en cualquier lugar del documento |
.// | Todos los elementos que son descendientes del contexto en curso |
nodo1 | Todos los elementos que son descendientes del nodo nodo1 en el contexto en curso |
nodo1/nodo11 | Todos los elementos nodo11 cuyo padre es nodo1 en el contexto en curso |
nodo1//nodonn | Todos los elementos nodonn que tienen de ancestro el nodo nodo1 en el contexto en curso |
session/paran[1] | El primer param hijo de todos los hijos de seccion del contexto en curso |
section/*/note | Elementos <note> que tienen de abuelo <section> |
stockquote[@symbol] | Elementos <stockquote> que tienen un atributo 'symbol' |
stockquote[@symbol='XXXX'] | Elementos <stockquote> que tienen un atributo 'symbol' igual a 'xxxx' |
emphasis|strong | Elementos emphasis o strong |
nodetest[1] | Primer nodo |
nodetest[position()=last()] | Último nodo |
nodetest[position() mod 2 = 0] | Nodos pares |
element[@id='foo'] | Nodos elementos cuyo valor de atributo es 'foot' |
./author
Note that this is equivalent to the following.
author
Find all first.name elements.
first.name
Find the document element (bookstore) of this document.
/bookstore
Find all author elements that are children of the current context node (for example, /bookstore/book).
//author
Find all bookstores where the value of the specialty attribute is equal to 'textbooks'.
/bookstore[@specialty = 'textbooks']
Find all books where the value of the style attribute on the book is equal to the value of the specialty attribute of the bookstore element at the root of the document.
book[/bookstore/@specialty = @style]
Find all first-name elements within an author element. Note that the author children of the current context are found, and then first-name children are found relative to the context of the author elements.
author/first-name
Find all title elements one or more levels deep in the bookstore (arbitrary descendants).
bookstore//title
Note that this is different from the following pattern, which finds all title elements that are grandchildren of bookstore elements.
bookstore/*/title
Find emph elements anywhere inside book excerpts, anywhere inside the bookstore.
bookstore//book/excerpt//emph
Find all titles one or more levels deep in the current context. Note that this situation is essentially the only one in which the period notation is required.
.//title
Find all element children of author elements.
author/*
Find all last names that are grandchildren of books.
book/*/last-name
Find the grandchildren elements of the current context.
*/*
Find the book element from the 'my' namespace.
my:book
Find all elements from the 'my' namespace.
my:*
Find all elements with the specialty attribute.
*[@specialty]
Find the style attribute of the current element context.
@style
Find the exchange attribute on price elements within the current context.
price/@exchange
The following example does not return anything because attributes do not contain element children. It is allowed by the XML Path Language (XPath) grammar, but is not strictly valid.
price/@exchange/total
Find all books with style attributes.
book[@style]
Find the style attribute for all book elements.
book/@style
Find all attributes of the current element context.
@*
Find all attributes from the 'my' namespace. This does not include unqualified attributes on elements from the 'my' namespace.
@my:*
Find all first-name elements. The following examples are equivalent.
./first-name
first-name
Find all unqualified book elements.
book
For example, the following finds the first author element.
author[1]
The following finds the third author element that has a first-name.
author[first-name][3]
Note that indexes are relative to the parent. Consider the following data.
<x>
<y/>
<y/>
</x>
<x>
<y/>
<y/>
</x>
Find the first y from each x.
x/y[1]
x/y[position() = 1]
Find the first y from the entire set of y elements within x elements.
(x/y)[1]
Find the second y from the first x.
x[1]/y[2]
Find the last book.
book[last()]
Find the last author for each book.
book/author[last()]
Find the last author from the entire set of authors of books.
(book/author)[last()]
Find all books that contain at least one excerpt element.
book[excerpt]
Find all titles of books that contain at least one excerpt element.
book[excerpt]/title
Find all authors of books where the book contains at least one excerpt and the author has at least one degree.
book[excerpt]/author[degree]
Find all books that have authors with at least one degree.
book[author/degree]
Find all books that have an excerpt and a title.
book[excerpt][title]
Find all author elements that contain at least one degree and one award.
author[degree and award]
Find all author elements that contain at least one degree or award and at least one publication.
author[(degree or award) and publication]
Find all author elements that contain at least one degree element and that contain no publication elements.
author[degree and not(publication)]
Find all author elements that contain publication elements but do not contain either degree elements or award elements.
author[not(degree or award) and publication]
Find all author elements that contain a last-name element with the value Bob.
author[last-name = 'Bob']
Find all author elements where the first last-name is Bob.
author[last-name[1] = 'Bob']
author[last-name = 'Bob']
Find all authors where the from attribute is not equal to 'Harvard'.
degree[@from != 'Harvard']
Find all authors where the last name is the same as the /guest/last-name element. (This assumes there is only one last-name. See Set Operations.)
author[last-name = /guest/last-name]
Find all authors whose text is 'Matthew Bob'.
author[. = 'Matthew Bob']
Find all author elements whose last name is 'Bob' and whose price is > 50. (This assumes there is only one last-name and price for an author. See Set Operations.)
author[last-name = 'Bob' and price > 50]
Find all authors whose last name begins with 'M' or greater.
author[last-name > 'M']
When an author can have several last names in the schema (for example, Clemens and Twain), use the following patterns.
author[all last-name >= 'M']
Find the first three books (1, 2, 3).
book[position() <= 3]
Find all author elements where any one of the last names is Bob.
author[last-name = 'Bob']
Find all author elements where none of the last-name elements is Bob.
author[not(last-name = 'Bob')]
Find all author elements containing a first-name child whose text is 'Bob'. (This and the following examples assume there is only one first-name child for an author.)
author[first-name = 'Bob']
Find all author elements containing any child element whose text is 'Bob'.
author[* = 'Bob']
Find author elements equal to 'Joe Bob'.
author[last-name = 'Bob' and first-name = 'Joe']
Find the intl attribute equal to 'Canada'.
price[@intl = 'Canada']
Find the first 3 degrees:
degree[position() < 3]
Find the second text node in each p element in the current context.
p/text()[2]
Find the nearest book ancestor of the current element.
ancestor::book[1]
Find the nearest ancestor author element that is contained in a book element.
ancestor::book[author][1]
To illustrate unions, consider the following data.
<root>
<x/> <!-- green -->
<y>
<x/> <!-- blue -->
<x/> <!-- blue -->
</y>
<z>
<x/>
<x/>
</z>
<x/> <!-- green -->
</root>
Find both green and blue nodes.
x | y/x
Comunicación HTML | |||||
Cliente | HTTP | Servidor Web | Lenguaje | Servidor BDatos | |
Solicita página html | |||||
Visualiza información html recibida | Sirve la página html, gif, jpg | ||||
Comunicación asp | |||||
Cliente | HTTP | Servidor Web | Lenguaje | Servidor BDatos | |
Solicita página asp sin envio de datos | Ejecuta página asp fuente | ||||
Procesa información | |||||
Visualiza información recibida | Sirve archivo asp de resultados | ||||
Comunicación asp a base de datos relacional (RDB) | |||||
Cliente | HTTP | Servidor Web | Lenguaje | Servidor BDatos | |
Solicita página asp y envia datos. (formulario) | Ejecuta página asp fuente | ||||
Realiza SQL | Ejecuta SQL | ||||
Procesa información | Sirve resultados | ||||
Visualiza información recibida | Sirve archivo asp de resultados | ||||
Comunicación XML sin Procesador XSLT | |||||
Cliente | HTTP | Servidor Web | Lenguaje | Servidor BDatos | |
Solicita página XML sin transformación | |||||
Visualiza información recibida en arbol (Procesador XMLT) | Sirve la página XML | ||||
Comunicación XML con Procesador XSLT en cliente | |||||
Cliente | HTTP | Servidor Web | Lenguaje | Servidor BDatos | |
Solicita página XML con transformación (XSL) | |||||
Realiza la transformación (Procesador XSLT) | Sirve la página XML y XSL | ||||
Visualiza información de transformación | |||||
Comunicación XML con Procesador XSLT en servidor | |||||
Cliente | HTTP | Servidor Web (DOM) | Lenguaje | Servidor BDatos | |
Solicita página XML con transformación XSL | Realiza la transformación a HTML (API XSLT) | ||||
Visualiza la información | Sirve el resultado en html o XML. | ||||
Comunicación asp a base de datos XML | |||||
Cliente | HTTP | Servidor Web (DOM,ADO) | Lenguaje | Servidor BDatos | |
Solicita página asp y envia datos. (formulario) | Ejecuta página asp fuente | ||||
Realiza XPath | Ejecuta XPath | ||||
Procesa información | Sirve resultados XML | ||||
Visualiza información recibida | Sirve archivo asp de resultados | ||||
Dos aplicaciones con comunicación de datos XML y acceso RDB y XML | |||||
Solicita página asp y envia datos. (formulario) | Ejecuta página asp fuente | ||||
Realiza SQL o SQL*(sql a xml) | ADO+SQL o ADO+XML | Ejecuta SQL o XML | |||
Procesa información | Sirve resultados | ||||
Sirve archivo asp de resultados a servidor 2 | |||||
Servidor 2 | Envia datos XML a otra aplicación. | Recibe y procesa datos XML de otra aplicación | |||
Servidor 2 | Ejecuta página asp fuente con datos dados por Servidor 1 | Ejecuta página asp fuente con datos dados por Servidor 1 | |||
Servidor 2 | Realiza XPath | Realiza XPath | |||
Servidor 2 | Procesa información | Procesa información | |||
Servidor 2 | Sirve archivo asp de resultados a Servidor 1 | Sirve archivo asp de resultados a Servidor 1 | |||
Visualiza información recibida | Servidor 1 sirve asp de resultados a cliente | Servidor 1 sirve asp de resultados a cliente |
<html> <body> <script type='text/vbscript'> txt='<h1>Traversing the node tree</h1>' document.write(txt) set xmlDoc=CreateObject('Microsoft.XMLDOM') 'Crea un arbol DOM xmlDoc.async='false' xmlDoc.load('note.xml') ' lee el archivo note.xml y lo pone en el arbol DOM for each x in xmlDoc.documentElement.childNodes ' barre el arbol DOM y obtiene un nodo document.write('<b>' & x.nodename & '</b>') ' escribe el nombre del nodo en una página html document.write(': ') document.write(x.text) document.write('<br/>') next </script> </body> </html>
Página generada automáticamente desde la Base de Datos: XML/ el 28/3/2008 13:14:59