xml - 如何在新属性中复制属性值

标签 xml xpath xquery sqlxml

如何将属性的数据复制到sql中同一列中的新属性

原始数据

<root>
<child attr='hello'></child>
</root>

结果 1
<root>
<child attr='hello' attr2='hello'></child>
</root>

结果2(有修改)
<root>
<child attr='hello' attr2='**H**ello **W**orld'></child>
</root>

我只想通过 SQL XML Xquery 执行此操作

最佳答案

我不确定我是否在第二个结果中完全遵循了您想要的内容,但我会尝试一下:下面的第一个示例将产生您的结果 #1(我已将您的原始数据放入 test.xml并假设在您的真实数据中可能会重复“child”和“attr”):

<root>{
  for $child in doc('test.xml')/root/*
  return
    element {name($child)} {
      for $attr at $index in $child/@*
      return (
        attribute {name($attr)} {$attr},
        attribute {concat(name($attr), 2)} {$attr}
      )
    }
}</root>

可以对其进行修改以放入不同的值,例如结果 #2,如下所示:
<root>{
  for $child in doc('test.xml')/root/*
  return
    element {name($child)} {
      for $attr at $index in $child/@*
      return (
        attribute {name($attr)} {$attr},
        attribute {concat(name($attr), 2)} {
          '**H**ello **W**orld' 
        }
      )
    }
}</root>

希望有帮助。

关于xml - 如何在新属性中复制属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2605532/

相关文章:

python 在 xml 文件中编码'(引用)

html - 如何通过XPath选择以特定的子项开头的子项

xpath - 如果 XQuery 包含给定关键字,则返回文本节点

c# - Selenium-如何迭代网页以查找所有必要的元素并执行单击操作

javascript - 在 MarkLogic 中使用 REST API 搜索调用仅提取部分 JSON 文档

ubuntu - 适用于 Ubuntu 的最佳 XQuery IDE

python - 如何在 Python 中捕获 XML 响应的第一行?

ruby - 如何使 xpath 表达式仅读取文档的一部分 (Ruby/Nokogiri/xpath)

python - 如何使用python从xml文件中获取值

xpath - 使用XPath检查Soap Envelope是否包含子节点