简体   繁体   English

立即用 Xquery/XUpdate 替换 xml 文档的所有元素

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

Given the following xml file:给定以下 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>

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

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. PS.Stackoverflow 论坛上仍然没有“XUpdate”标签。 It would be nice if someone added it.如果有人添加它会很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM