用XqueryXUpdate一次性替换xml文档中的所有元素。

问题描述 投票:0回答:1

给出以下xml文件。

<?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>

我想把所有的 "color "元素替换成 "white"。这是我的尝试。

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

谢谢你

xquery
1个回答
3
投票

比预期的要容易得多

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

PS.在Stackoverflow论坛上仍然没有 "XUpdate "标签. 如果有人能增加这个标签就更好了。

© www.soinside.com 2019 - 2024. All rights reserved.