HOTOMOL
HOTOMOL

Reputation: 75

Replace at once all the elements of an xml document with Xquery/XUpdate

Given the following xml file:

<?xml-stylesheet type="text/xsl" href="cars.xsl"?>
<garagexmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="cars.xsd"><!--Enlazar su XSD-->
  <car>
    <color>red</color>
    <power>120</power>  
    <seats>5</seats>  
    <price>33500</price> 
  </car>
  <car>
    <color>white</color>
    <power>120</power> 
    <seats>5</seats> 
    <price>23500</price>
  </car>
  <car>
    <color>blue</color>
    <power>200</power> 
    <seats>5</seats>  
    <price>45500</price> 
  </car>
</garage>

I want to replace all the 'color' elements so that its content is "white". Here is my try:

update replace /garage/car/color[.="*"]
with "white"

Thanks

Upvotes: 1

Views: 77

Answers (1)

HOTOMOL
HOTOMOL

Reputation: 75

It was easier than expected:

  update replace /garage/car/color
    with <color>white</color>

PS.There is still no 'XUpdate' tag on the Stackoverflow forum. It would be nice if someone added it.

Upvotes: 3

Related Questions