<tfoot id='jgovf'></tfoot>
  • <i id='jgovf'><tr id='jgovf'><dt id='jgovf'><q id='jgovf'><span id='jgovf'><b id='jgovf'><form id='jgovf'><ins id='jgovf'></ins><ul id='jgovf'></ul><sub id='jgovf'></sub></form><legend id='jgovf'></legend><bdo id='jgovf'><pre id='jgovf'><center id='jgovf'></center></pre></bdo></b><th id='jgovf'></th></span></q></dt></tr></i><div id='jgovf'><tfoot id='jgovf'></tfoot><dl id='jgovf'><fieldset id='jgovf'></fieldset></dl></div>
  • <legend id='jgovf'><style id='jgovf'><dir id='jgovf'><q id='jgovf'></q></dir></style></legend>

      <small id='jgovf'></small><noframes id='jgovf'>

        • <bdo id='jgovf'></bdo><ul id='jgovf'></ul>

        SQL Server 生成带有通用字段元素的 XML

        时间:2023-06-07
          <legend id='f4Ifs'><style id='f4Ifs'><dir id='f4Ifs'><q id='f4Ifs'></q></dir></style></legend>
              <bdo id='f4Ifs'></bdo><ul id='f4Ifs'></ul>

              <small id='f4Ifs'></small><noframes id='f4Ifs'>

                <tbody id='f4Ifs'></tbody>

            • <tfoot id='f4Ifs'></tfoot>

                <i id='f4Ifs'><tr id='f4Ifs'><dt id='f4Ifs'><q id='f4Ifs'><span id='f4Ifs'><b id='f4Ifs'><form id='f4Ifs'><ins id='f4Ifs'></ins><ul id='f4Ifs'></ul><sub id='f4Ifs'></sub></form><legend id='f4Ifs'></legend><bdo id='f4Ifs'><pre id='f4Ifs'><center id='f4Ifs'></center></pre></bdo></b><th id='f4Ifs'></th></span></q></dt></tr></i><div id='f4Ifs'><tfoot id='f4Ifs'></tfoot><dl id='f4Ifs'><fieldset id='f4Ifs'></fieldset></dl></div>
                  本文介绍了SQL Server 生成带有通用字段元素的 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我基本上是想扭转这个问题的要求......SQL Server 查询元素值的 xml 属性

                  I'm basically trying to reverse what this question is asking... SQL Server query xml attribute for an element value

                  我需要生成一个row"元素的结果集,其中包含一组field"元素,其属性定义了键.

                  I need to produce a result set of "row" elements that contain a group of "field" elements with an attribute that defines the key.

                  <resultset statement="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <row>
                      <field name="id">1</field>
                      <field name="version">0</field>
                      <field name="property">My Movie</field>
                      <field name="release_date">2012-01-01</field>
                      <field name="territory_code">FR</field>
                      <field name="territory_description">FRANCE</field>
                      <field name="currency_code">EUR</field>
                  </row>
                  <row>
                      <field name="id">2</field>
                      <field name="version">0</field>
                      <field name="property">My Sequel</field>
                      <field name="release_date">2014-03-01</field>
                      <field name="territory_code">UK</field>
                      <field name="territory_description">United Kingdom</field>
                      <field name="currency_code">GBP</field>
                  </row>
                  </resultset>
                  

                  我有一个查询返回这个...

                  I've got a query that returns this...

                  <resultset statement="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                  <row>
                      <id>1</id>
                      <version>0</version>
                      <property>My Movie</property>
                      <release_date>2012-01-01</release_date>
                      <territory_code>FR</territory_code>
                      <territory_description>FRANCE</territory_description>
                      <currency_code>EUR</currency_code>
                  </row>
                  <row>
                      <id>2</id>
                      <version>0</version>
                      <property>My Sequel</property>
                      <release_date>2014-03-01</release_date>
                      <territory_code>UK</territory_code>
                      <territory_description>UNITED KINGDOM</territory_description>
                      <currency_code>GBP</currency_code>
                  </row>
                  </resultset>
                  

                  在我的 SQL 语句中使用 FOR XML PATH ('row'), ROOT ('resultset').

                  Using FOR XML PATH ('row'), ROOT ('resultset') in my SQL statement.

                  我错过了什么?谢谢.

                  推荐答案

                  它有点涉及 SQL Server - 正常行为就是您所看到的 - 列名称将用作 XML 元素名称.

                  It's a bit involved in SQL Server - the normal behavior is what you're seeing - the column names will be used as XML element names.

                  如果您真的希望所有 XML 元素都具有相同的名称,则必须使用如下代码:

                  If you really want all XML elements to be named the same, you'll have to use code something like this:

                  SELECT
                      'id' AS 'field/@name',
                      id AS 'field',
                      '',
                      'version' AS 'field/@name',
                      version AS 'field',
                      '',
                      'property' AS 'field/@name',
                      property AS 'field',
                      '',
                      ... and so on ....
                  FROM Person.Person
                  FOR XML PATH('row'),ROOT('resultset')
                  

                  这是必要的,以确保将列名用作 元素上的 name 属性,并且需要空字符串,以便 SQLXML 解析器不会混淆哪个 name 属性属于哪个元素......

                  This is necessary to make sure the column name is used as the name attribute on the <field> element, and the empty string are necessary so that the SQL XML parser doesn't get confused about which name attribute belongs to what element......

                  这篇关于SQL Server 生成带有通用字段元素的 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在忽略命名空间的同时查询 XML? 下一篇:在 T-SQL 中通过 XQuery 选择时连接 xml 值

                  相关文章

                  最新文章

                • <i id='qMZqn'><tr id='qMZqn'><dt id='qMZqn'><q id='qMZqn'><span id='qMZqn'><b id='qMZqn'><form id='qMZqn'><ins id='qMZqn'></ins><ul id='qMZqn'></ul><sub id='qMZqn'></sub></form><legend id='qMZqn'></legend><bdo id='qMZqn'><pre id='qMZqn'><center id='qMZqn'></center></pre></bdo></b><th id='qMZqn'></th></span></q></dt></tr></i><div id='qMZqn'><tfoot id='qMZqn'></tfoot><dl id='qMZqn'><fieldset id='qMZqn'></fieldset></dl></div>

                    <small id='qMZqn'></small><noframes id='qMZqn'>

                    <legend id='qMZqn'><style id='qMZqn'><dir id='qMZqn'><q id='qMZqn'></q></dir></style></legend>

                    <tfoot id='qMZqn'></tfoot>
                      • <bdo id='qMZqn'></bdo><ul id='qMZqn'></ul>