繁体   English   中英

XML返回单独的节点元素

[英]XML return into separate node elements

我需要以特定格式返回结果

<Applicants xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Applicant>
        <Name>John Smith</Name>
        <Address>1 Smiths Close</Address>
    </Applicant>
    <Applicant>
        <Name>Peter Smith</Name>
        <Address>2 Smiths Close</Address>
    </Applicant>
</Applicants>

但是用我当前的查询

select A.Name
    , ANL.name
    , A.address AS Address
    , ANL.address AS Address
    from Agents A 
        left join AgentsNonLatin ANL 
            On A.Pn = ANL.Pn AND A.Kd = ANL.kd 
    FOR XML RAW('Applicant'), ROOT('Applicants'), ELEMENTS XSINIL

我将它们合并到单个<Applicant>节点中。

<Applicants xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Applicant>
    <Name>John Smith</Name>
    <Name>Peter Smith</Name>
    <Address>1 Smiths Close</Address>
    <Address>2 Smiths Close</Address>
  </Applicant>
</Applicants>

关于需要更改以按要求的格式返回它们的任何想法?

在这里使用联盟

SELECT 
      A.Name
    , A.Address 
    FROM Agents A 
UNION
SELECT 
      ANL.Name
    , ANL.Address AS Address
    FROM AgentsNonLatin ANL 
FOR XML RAW('Applicant'), ROOT('Applicants'), ELEMENTS XSINIL

暂无
暂无

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

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