<bdo id='HpVPy'></bdo><ul id='HpVPy'></ul>

  • <small id='HpVPy'></small><noframes id='HpVPy'>

    <tfoot id='HpVPy'></tfoot>

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

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

        使用 SQL 编辑 XML 列.不那么结构化的 XML

        时间:2023-06-07
        <legend id='tNHlt'><style id='tNHlt'><dir id='tNHlt'><q id='tNHlt'></q></dir></style></legend>
      1. <i id='tNHlt'><tr id='tNHlt'><dt id='tNHlt'><q id='tNHlt'><span id='tNHlt'><b id='tNHlt'><form id='tNHlt'><ins id='tNHlt'></ins><ul id='tNHlt'></ul><sub id='tNHlt'></sub></form><legend id='tNHlt'></legend><bdo id='tNHlt'><pre id='tNHlt'><center id='tNHlt'></center></pre></bdo></b><th id='tNHlt'></th></span></q></dt></tr></i><div id='tNHlt'><tfoot id='tNHlt'></tfoot><dl id='tNHlt'><fieldset id='tNHlt'></fieldset></dl></div>

                <tbody id='tNHlt'></tbody>

                <tfoot id='tNHlt'></tfoot>

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

                • <bdo id='tNHlt'></bdo><ul id='tNHlt'></ul>
                • 本文介绍了使用 SQL 编辑 XML 列.不那么结构化的 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  如何通过获取XXX"的新标签来编辑 XML,而不是结构化的 xml.需要帮助,我对 XML 和 XQuery 非常陌生.如果 X 没有,则必须为 X 获取新标签(节点),在 1 的情况下只需要插入 1.有没有办法在更大范围内操作字符串

                  How to edit XML by getting new tags for 'XXX', not so structured xml. Need help, I am very new to XML and XQuery. Have to get new tags (nodes) for X if it is none, in case of 1 need to insert 1 only. is there any way to manipulate string on larger scale

                  <NewAttributeRules>
                  <items>
                  <NewAttributeItem>
                    <Scale>CAAA</Scale>
                    <ScaleName>OC07</ScaleName>
                    <comment />
                    <positiveRules>
                      <NewAttributeRule type="POSITIVE">
                        <conditions>
                          <InCondition column="PPRD" colDataType="STRING">
                            <values>
                              <string>CAAAEXTENDED</string>
                            </values>
                          </InCondition>
                        </conditions>
                      </NewAttributeRule>
                    </positiveRules>
                    <negativeRules />
                   </NewAttributeItem>
                  
                  
                   <NewAttributeItem>
                    <Scale>high TOTAL OTHERS</Scale>
                    <ScaleName>b007</ScaleName>
                    <comment />
                    <positiveRules>
                      <NewAttributeRule type="POSITIVE">
                        <conditions>
                          <InCondition column="ATC3" colDataType="STRING">
                            <values>
                              <string>B10787 EXT</string>
                            </values>
                          </InCondition>
                        </conditions>
                      </NewAttributeRule>
                    </positiveRules>
                    <negativeRules>
                      <NewAttributeRule type="NEGATIVE">
                        <conditions>
                          <InCondition column="PPRD" colDataType="STRING">
                            <values>
                              <string>hkJKKK</string>
                              <string>GAGHA</string>
                              </values>
                          </InCondition>
                        </conditions>
                      </NewAttributeRule>
                      </negativeRules>
                     </NewAttributeItem>
                        
                  
                  <NewAttributeItem>
                    <Scale>***XXX***</Scale>
                    <ScaleName>OC07</ScaleName>
                    <comment />
                    <positiveRules />
                    <negativeRules />
                  </NewAttributeItem>
                  <NewAttributeItem>
                    <Scale>***XXX***</Scale>
                    <ScaleName>OC07</ScaleName>
                    <comment />
                    <positiveRules />
                    <negativeRules />
                   </NewAttributeItem>
                  
                  <NewAttributeItem>
                    <Scale>***XXX***</Scale>
                    <ScaleName>b007</ScaleName>
                    <comment />
                    <positiveRules />
                    <negativeRules />
                   </NewAttributeItem>
                  <NewAttributeItem>
                    <Scale>***XXX***</Scale>
                    <ScaleName>b007</ScaleName>
                    <comment />
                    <positiveRules />
                    <negativeRules />
                   </NewAttributeItem>
                  
                  </items>
                  </NewAttributeRules>
                  

                  推荐答案

                  好的,现在 XML 是有效的...

                  Okay, now the XML is valid...

                  连同来自您的其他问题的信息,我建议采用这种方法:

                  Together with the information form your other question I'd suggest this approach:

                  我把你的 XML 放入一个声明的变量中

                  I put your XML into a declared variable

                  declare @xml xml=
                  N'<NewAttributeRules>
                    <items>
                      <NewAttributeItem>
                        <Scale>CAAA</Scale>
                        <ScaleName>OC07</ScaleName>
                        <comment />
                        <positiveRules>
                          <NewAttributeRule type="POSITIVE">
                            <conditions>
                              <InCondition column="PPRD" colDataType="STRING">
                                <values>
                                  <string>CAAAEXTENDED</string>
                                </values>
                              </InCondition>
                            </conditions>
                          </NewAttributeRule>
                        </positiveRules>
                        <negativeRules />
                      </NewAttributeItem>
                      <NewAttributeItem>
                        <Scale>high TOTAL OTHERS</Scale>
                        <ScaleName>b007</ScaleName>
                        <comment />
                        <positiveRules>
                          <NewAttributeRule type="POSITIVE">
                            <conditions>
                              <InCondition column="ATC3" colDataType="STRING">
                                <values>
                                  <string>B10787 EXT</string>
                                </values>
                              </InCondition>
                            </conditions>
                          </NewAttributeRule>
                        </positiveRules>
                        <negativeRules>
                          <NewAttributeRule type="NEGATIVE">
                            <conditions>
                              <InCondition column="PPRD" colDataType="STRING">
                                <values>
                                  <string>hkJKKK</string>
                                  <string>GAGHA</string>
                                </values>
                              </InCondition>
                            </conditions>
                          </NewAttributeRule>
                        </negativeRules>
                      </NewAttributeItem>
                      <NewAttributeItem>
                        <Scale>***XXX***</Scale>
                        <ScaleName>OC07</ScaleName>
                        <comment />
                        <positiveRules />
                        <negativeRules />
                      </NewAttributeItem>
                      <NewAttributeItem>
                        <Scale>***XXX***</Scale>
                        <ScaleName>OC07</ScaleName>
                        <comment />
                        <positiveRules />
                        <negativeRules />
                      </NewAttributeItem>
                      <NewAttributeItem>
                        <Scale>***XXX***</Scale>
                        <ScaleName>b007</ScaleName>
                        <comment />
                        <positiveRules />
                        <negativeRules />
                      </NewAttributeItem>
                      <NewAttributeItem>
                        <Scale>***XXX***</Scale>
                        <ScaleName>b007</ScaleName>
                        <comment />
                        <positiveRules />
                        <negativeRules />
                      </NewAttributeItem>
                    </items>
                  </NewAttributeRules>';
                  

                  --和之前一样,CTE 将读取 ScaleName 以供稍后分组,但会让整个节点 保持原样

                  --As before, the CTE will read the ScaleName for later grouping, but will let the whole node as is

                  WITH ScaleNames AS
                  (
                      SELECT  ai.query('.') AS AiNode
                             ,ai.value('(ScaleName)[1]','nvarchar(100)') AS ScaleName
                      FROM @xml.nodes('/NewAttributeRules/items/NewAttributeItem') AS A(ai)
                      WHERE ai.value('(Scale)[1]','nvarchar(100)')<>'***XXX***'
                  )
                  

                  --此 SELECT 将使用现有节点重建整个 XML,并添加两倍的 XXX 节点.

                  --This SELECT will rebuild the whole XML using the existing nodes and adding two times the XXX nodes.

                  SELECT
                  (
                      SELECT (
                                  SELECT x.AiNode AS [node()]
                                  FROM ScaleNames AS x
                                  WHERE x.ScaleName=ScaleNames.ScaleName
                                  FOR XML PATH(''),TYPE
                             ) AS [node()]
                            ,(SELECT
                               (SELECT '***XXX***' AS Scale, ScaleName, '' AS comment, '' AS positiveRules, '' AS negativRules FOR XML PATH('NewAttributeItem'),TYPE )
                              ,(SELECT '***XXX***' AS Scale, ScaleName, '' AS comment, '' AS positiveRules, '' AS negativRules FOR XML PATH('NewAttributeItem'),TYPE)
                              FOR XML PATH(''),TYPE
                             ) AS [node()]
                      FROM ScaleNames
                      GROUP BY ScaleName
                      ORDER BY ScaleName
                      FOR XML PATH(''),ROOT('items'),TYPE
                  )
                  FOR XML PATH(''),ROOT('NewAttributeRules')
                  

                  结果

                  <NewAttributeRules>
                    <items>
                      <NewAttributeItem>
                        <Scale>high TOTAL OTHERS</Scale>
                        <ScaleName>b007</ScaleName>
                        <comment />
                        <positiveRules>
                          <NewAttributeRule type="POSITIVE">
                            <conditions>
                              <InCondition column="ATC3" colDataType="STRING">
                                <values>
                                  <string>B10787 EXT</string>
                                </values>
                              </InCondition>
                            </conditions>
                          </NewAttributeRule>
                        </positiveRules>
                        <negativeRules>
                          <NewAttributeRule type="NEGATIVE">
                            <conditions>
                              <InCondition column="PPRD" colDataType="STRING">
                                <values>
                                  <string>hkJKKK</string>
                                  <string>GAGHA</string>
                                </values>
                              </InCondition>
                            </conditions>
                          </NewAttributeRule>
                        </negativeRules>
                      </NewAttributeItem>
                      <NewAttributeItem>
                        <Scale>***XXX***</Scale>
                        <ScaleName>b007</ScaleName>
                        <comment />
                        <positiveRules />
                        <negativRules />
                      </NewAttributeItem>
                      <NewAttributeItem>
                        <Scale>***XXX***</Scale>
                        <ScaleName>b007</ScaleName>
                        <comment />
                        <positiveRules />
                        <negativRules />
                      </NewAttributeItem>
                      <NewAttributeItem>
                        <Scale>CAAA</Scale>
                        <ScaleName>OC07</ScaleName>
                        <comment />
                        <positiveRules>
                          <NewAttributeRule type="POSITIVE">
                            <conditions>
                              <InCondition column="PPRD" colDataType="STRING">
                                <values>
                                  <string>CAAAEXTENDED</string>
                                </values>
                              </InCondition>
                            </conditions>
                          </NewAttributeRule>
                        </positiveRules>
                        <negativeRules />
                      </NewAttributeItem>
                      <NewAttributeItem>
                        <Scale>***XXX***</Scale>
                        <ScaleName>OC07</ScaleName>
                        <comment />
                        <positiveRules />
                        <negativRules />
                      </NewAttributeItem>
                      <NewAttributeItem>
                        <Scale>***XXX***</Scale>
                        <ScaleName>OC07</ScaleName>
                        <comment />
                        <positiveRules />
                        <negativRules />
                      </NewAttributeItem>
                    </items>
                  </NewAttributeRules>
                  

                  这篇关于使用 SQL 编辑 XML 列.不那么结构化的 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 T-SQL 中查询之前将字符串转换为 XML 数据类型 下一篇:为 SQL 表中的每一行粉碎 XML

                  相关文章

                  最新文章

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

                        <bdo id='Vhp1i'></bdo><ul id='Vhp1i'></ul>

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

                    1. <tfoot id='Vhp1i'></tfoot>
                      <legend id='Vhp1i'><style id='Vhp1i'><dir id='Vhp1i'><q id='Vhp1i'></q></dir></style></legend>