用for xml auto 子句得到如下表,但是不能在页面显示,
<test ID="1" col1="1" col2="b" col3="1" />
<test ID="2" col1="1" col2="c" col3="4" />
<test ID="3" col1="1" col2="a" col3="9" />
<test ID="4" col1="1" col2="b" col3="16" />
<test ID="5" col1="1" col2="c" col3="25" />
<test ID="6" col1="1" col2="a" col3="36" />
<test ID="7" col1="1" col2="b" col3="49" />
用ExecuteScalar()方法截断,用什么方法在页显示xml,依然以xml格式

解决方案 »

  1.   

    XMLFiel1.xml<?xml version="1.0" encoding="utf-8" ?>
    <?xml-stylesheet type="text/xsl" href="XSLTFile1.xslt"?>
    <t>
      <test ID="1" col1="1" col2="b" col3="1" >a</test>
      <test ID="2" col1="1" col2="c" col3="4" >b</test>
      <test ID="3" col1="1" col2="a" col3="9" >c</test>
      <test ID="4" col1="1" col2="b" col3="16" >d</test>
      <test ID="5" col1="1" col2="c" col3="25" >e</test>
      <test ID="6" col1="1" col2="a" col3="36" >f</test>
      <test ID="7" col1="1" col2="b" col3="49" >g</test>
    </t>
    XSLTFile1.xslt
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
    >
        <xsl:output method="xml" indent="yes"/>    <xsl:template match="@* | node()">
            <xsl:copy>
                <xsl:apply-templates select="@* | node()"/>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
      

  2.   

    3Q ,to yoursWTR
    我知道用dataTable.WriteXml()  方法可以实现xml页面输出。我想实现在页面显示如下形式<?xml version="1.0" encoding="utf-8" ?>
    <t>
      <test ID="1" col1="1" col2="b" col3="1" >a</test>
      <test ID="2" col1="1" col2="c" col3="4" >b</test>
      <test ID="3" col1="1" col2="a" col3="9" >c</test>
      <test ID="4" col1="1" col2="b" col3="16" >d</test>
      <test ID="5" col1="1" col2="c" col3="25" >e</test>
      <test ID="6" col1="1" col2="a" col3="36" >f</test>
      <test ID="7" col1="1" col2="b" col3="49" >g</test>
    </t>
    怎么实现?但不是这样的显示
     <?xml version="1.0" encoding="UTF-8" ?> 
    - <DocumentElement>
    - <test>
      <ID>1</ID> 
      <col1>1</col1> 
      <col2>b</col2> 
      <col3>1</col3> 
      </test>
    - <test>
      <ID>2</ID> 
      <col1>1</col1> 
      <col2>c</col2> 
      <col3>4</col3> 
      </examList>
    - <test>
      <ID>3</ID> 
      <col1>1</col1> 
      <col2>a</col2> 
      <col3>9</col3> 
      </test>
    - <test>
      <ID>4</ID> 
      <col1>1</col1> 
      <col2>b</col2> 
      <col3>16</col3> 
      </test>
    </DocumentElement>
      

  3.   

    我知道你什么意思了
    不是用ExecuteScalar() 而是用ExecuteXmlReader();System.Xml.XmlReader xr = Command.ExecuteXmlReader();
                xr.Read();
                while (!xr.EOF) 
                {
                    Response.Write(Server.HtmlEncode(xr.ReadOuterXml()));             
                }
                xr.Close();