Xupdate. Misión
•
La misión del grupo de trabajo Xupdate es la
proveer una abierta y flexible actualización para
modificar datos en documentos XML.
•
Pueden ser documentos reales o documentos
Xupdate. Definición
•
Es un lenguaje enfocado a la actualización de
bases de datos XML.
•
Analiza los archivos XML y generas las “tablas”
para el manejo de los documentos.
•
A pesar de un comienzo entusiasta, este se
encuentra virtualmente paralizado desde fines
del año 2000.
Xupdate. Select
•
Toda actualización, al igual que en cualquier
base de datos, requiere una selección de datos
sobre los cuales aplicar dichos cambios;
XUpdate continua con el estándar de utilizar
XPath para dicho propósito.
Xupdate. Modification
•
Toda modificación debe estar contenida en un
elemento xupdate:modifications el cual debe
contener un atributo indicando la versión de
XUpdate necesaria
Xupdate. Modification
•
A su vez, el elemento modifications debe contener
alguno de los siguientes elementos, dependiendo del
tipo de cambio a realizar:
▫
xupdate:insert-before
▫
xupdate:insert-after
▫
xupdate:append
▫
xupdate:update
▫
xupdate:remove
▫
xupdate:rename
▫
xupdate:variable
▫
xupdate:value-of
▫
xupdate:if
Xupdate.
•
Se puede modificar el contenido de un XML,
simplemente declarando que cambio debe de
hacerse en la sintaxis del XML.
•
Veremos
diferentes
Casos
de
Uso
Xupdate. Documento XML
<addresses>
<address id=“1”>
<!-
Este es el nombre del usuario
-->
<name>
<first>
John
</first>
<last>
Smith
</last>
</name>
<city>
Houston
</city>
<state>
Texas
</state>
<
country>United States
</country>
<phone type=“home”>
333-300-0300
</phone>
<phone type=“work”>3
33-500-9080
</phone>
<note><!-[
CDATA[Este es un nuevo usuario
]]></note>
</address>
Xupdate. Casos de Uso
•
Insert Element Before
•
Insert Element After
•
Append Element
•
Insert attribute
•
Insert Text Content
•
Insert XML Block
•
Insert a Processing
Instruction
•
Insert a Comment
•
Insert CDATA Content
•
Update Element
•
Update Attribute
•
Update Comment
•
Update CDATA
Content
•
Rename Element
•
Rename Attribute
•
Delete Element
•
Delete Attribute
•
Delete Text Content of
an Element
•
Delete Comment
•
Delete CDATA Content
•
Copying a Node
Xupdate. Casos de Uso.
Insert Element
Before
(Insertar elemento antes)
•
Adicionar un elemento medio “name” antes del
elemento “last name”
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:insert-before select="/addresses/address[@id = 1]/name/last" >
<xupdate:element name="middle">Lennox</xupdate:element>
</xupdate:insert-before>
Xupdate. Casos de Uso.
Insert Element
After
(Insertar elemento después)
•
Adicionar un elemento “cell phone” después del
elemento “home phone” .
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:insert-after select="/addresses/address[@id = 1]/phone[@type='home']" >
<xupdate:element name="phone"><xupdate:attribute
name="type">cell</xupdate:attribute>490-494-4904</xupdate:element>
</xupdate:insert-after> </xupdate:modifications>
Xupdate. Casos de Uso.
Append
Element
(Añadir elemento)
•
Añadir elemento “zip code” al registro de
“address”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:append select="/addresses/address[@id = 1]" >
<xupdate:element name="zip">90200</xupdate:element>
</xupdate:append>
</xupdate:modifications>
Xupdate. Casos de Uso.
Insert
Attribute
(Insertar atributo)
•
Insertar un atributo “extension” a elemento
“phone work”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:append select="/addresses/address[@id = 1]/phone[@type='work']" > <xupdate:attribute name="extension">223</xupdate:attribute>
</xupdate:append> </xupdate:modifications>
Xupdate. Casos de Uso.
Insert Text
Content
(Insertar contenido de texto)
•
Inserta la clausula “ of America” al elemento
“country”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:append select="/addresses/address[@id = 1]/country" >
<xupdate:text> of America</xupdate:text>
</xupdate:append>
Xupdate. Casos de Uso.
Insert XML
Block
(Insertar bloque XML)
•
Adicionar un nuevo registro de “address” a el nivel mas alto
del elemento “addresses”.
<xupdate:modifications version="1.0" xmlns:xupdate="http://www.xmldb.org/xupdate"> <xupdate:append select="/addresses" > <xupdate:element name="address"> <xupdate:attribute name="id">2</xupdate:attribute> <name> <first>Susan</first> <last>Long</last> </name> <city>Tucson</city> <state>Arizona</state> <country>United States</country> <phone type="home">430-304-3040</phone> </xupdate:element> </xupdate:append> </xupdate:modifications>
Processing Instruction
(Insertar una
instrucción de procesamiento)
•
Adicionar un simple XML, instrucción de
procesamiento a nivel de raíz del documento.
<
xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:insert-before select="/addresses">
<xupdate:processing-instruction
name="cocoon-process">type="xsp"</xupdate:processing-instruction>
</xupdate:insert-before>
</xupdate:modifications>
Comment
(Insertar comentario)
•
Adicionar otro comentario en el elemento
“name”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:insert-before select="/addresses/address[@id = 1]/name">
<xupdate:comment>Another comment about the name</xupdate:comment> </xupdate:insert-before>
Content
(Insertar contenido CDATA)
•
Añadir un elemento “note” con contenido
CDATA, con lagunas etiquetas HTML.
<
xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:append select="/addresses/address[@id = 1]" >
<xupdate:element name="note"><xupdate:cdata><![CDATA[A simple
<b>note</b>]]></xupdate:cdata></xupdate:element>
</xupdate:append>
Element
(Actualiza un elemento)
•
Cambiar el primer nombre de la dirección con
id=1, será Johnathan.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:update select="/addresses/address[@id = 1]/name/first">Johnathan</xupdate:update> </xupdate:modifications>
Attribute
(Actualiza un atributo)
•
Cambiar el tipo de numero telefónico
333-300-0300 para ser celular.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:update select="/addresses/address[@id =
1]/phone[.='333-300-0300']/@type" >cell</xupdate:update>
Comment
(Actualiza comentario)
•
Cambiar el comentario justo antes del elemento
“name” que empieza con “This”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:update select="/addresses/address[@id =
1]/comment()[starts-with(., 'This')]" >This user has a name.</xupdate:update>
Content
(Actualiza contenido CDATA)
•
Cambiar el CDATA, del elemento “note”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:update select="/addresses/address[@id = 1]/note/text()"
><![CDATA[Just some <i>modified</i> content]]></xupdate:update>
</xupdate:modifications>
Attribute
(Renombra atributo)
•
Renombrar el elemento “note” a “comment”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:rename select="/addresses/address[@id = 1]/note" >comment</xupdate:rename> </xupdate:modifications>
(Borra elemento)
•
Borrar todos los elementos “phone”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:remove select="/addresses/address[@id = 1]/phone"/>
</xupdate:modifications>
Attribute
(Borra atributo)
•
Borrar todos los atributos, del elemento “phone”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:remove select="/addresses/address[@id = 1]/phone/@type" />
</xupdate:modifications>
Content of an Element
(Borra el
contenido de texto de una elemento)
•
Borrar el contenido del elemento “country”.
<
xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:remove select="/addresses/address[@id = 1]/country/text()" />
</xupdate:modifications>
Comment
(Borra comentario)
•
Borrar el primer comentario antes del elemento
“name”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:remove select="/addresses/address[@id = 1]/comment()[1]" />
</xupdate:modifications>
Content
(Borra contenido CDATA)
•
Borrar el contenido CDATA del elemento “note”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:remove select="/addresses/address[@id = 1]/note/text()" />
</xupdate:modifications>
(Copia un nodo)
•
Copia el nodo “state” y el lugar de la copia después
de que el nodo “country”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:variable name="state" select="/addresses/address[@id = 1]/state"/> <xupdate:insert-after select="/addresses/address[@id = 1]/country">
<xupdate:value-of select="$state"/> </xupdate:insert-after>
(Moviendo un nodo)
•
Mover el nodo “country” antes del nodo “state”.
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:variable name="country" select="/addresses/address[@id = 1]/country"/> <xupdate:remove select="/addresses/address[@id = 1]/country"/>
<xupdate:insert-before select="/addresses/address[@id = 1]/state"> <xupdate:value-of select="$country"/>
</xupdate:insert-before>