我在 sqlserver进行了 xml查询 生成的xml是这样的
<ers>
  <community count="4" community_id="126" ID="126" community="高桥小区" Area_ID="1" Address="43-3-501" PinYin="gqxq" />
  <community count="1" community_id="127" ID="127" community="新惠明苑" Area_ID="1" Address="2-1-1002" PinYin="xhmy" />
  <community count="7" community_id="128" ID="128" community="育才东苑" Area_ID="1" Address="46-3-302" PinYin="ycdy" />
  <community count="2" community_id="129" ID="129" community="半岛花园" Area_ID="2" Address="26-202" PinYin="bdhy" />
  <community count="1" community_id="130" ID="130" community="半岛花园" Area_ID="2" Address="27-1-401" PinYin="bdhy" />
  <community count="1" community_id="131" ID="131" community="潘水南苑" Area_ID="1" Address="46-6-101" PinYin="psny" />
</ers>我想在程序中 直接输出这些 xml 
就像  response.write("xxxxxx");
输出字符串一样 
这应该如何做啊?

解决方案 »

  1.   

    declare @x xml
    set @x=
    '<ers>
      <community count="4" community_id="126" ID="126" community="高桥小区" Area_ID="1" Address="43-3-501" PinYin="gqxq" />
      <community count="1" community_id="127" ID="127" community="新惠明苑" Area_ID="1" Address="2-1-1002" PinYin="xhmy" />
      <community count="7" community_id="128" ID="128" community="育才东苑" Area_ID="1" Address="46-3-302" PinYin="ycdy" />
      <community count="2" community_id="129" ID="129" community="半岛花园" Area_ID="2" Address="26-202" PinYin="bdhy" />
      <community count="1" community_id="130" ID="130" community="半岛花园" Area_ID="2" Address="27-1-401" PinYin="bdhy" />
      <community count="1" community_id="131" ID="131" community="潘水南苑" Area_ID="1" Address="46-6-101" PinYin="psny" />
    </ers>'select convert(varchar(max), @x)
      

  2.   

    select * from  tb for xml path('ers/community')
      

  3.   

    我得到这个 xml是执行了一个存储过程 还是动态的sql生成的
    所以我生成的xml结果 放不到定义的xml变量中去啊怎么办啊
    @sql 是一个查询字符串 产生上面这个xmlexec(@sql)如何把 这个结果结放到定义的xml变量中去
      

  4.   

    你看看这里是否有你需要的内容?
    SQLServer2005 XML在T-SQL查询中的典型应用
    http://topic.csdn.net/u/20081107/17/68aaf5a9-c596-4ab5-ae18-f3370b2ab35b.html