使用WriteXML的C#自定义XML标记

时间:2017-07-05 13:10:47

标签: c# xml xslt

我正在从DataSet创建XML文件,但有三个问题,

1)我想从<分配表的自定义标签名称表>到< my_items>
2)在开始某些标签之前,我不明白减号( - )?
3)我想用它创建XSL文件也可以使用.WriteXML吗?

C#代码:

string connectionString = @"Connection string";           
    using(SqlConnection _con = new SqlConnection(connectionString))
    {
       using(SqlCommand _cmd = new SqlCommand("select * from items", _con))
       {            
          DataSet ds = new DataSet("oitm");
          SqlDataAdapter _dap = new SqlDataAdapter(_cmd);
          _con.Open();
          _dap.Fill(ds);
          ds.WriteXml("test.xml", XmlWriteMode.WriteSchema);
          _con.Close();
        }
    }

输出文件(test.xml

<?xml version="1.0" standalone="true"?>
-<oitm>

    -<xs:schema xmlns:msdata="urn:schemas_microsoft_com:xml_msdata" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" id="oitm">
    -<xs:element msdata:UseCurrentLocale="true" msdata:IsDataSet="true" name="oitm">
        -<xs:complexType>
          -<xs:choice maxOccurs="unbounded" minOccurs="0">
            -<xs:element name="Table">
              -<xs:complexType>
                -<xs:sequence>
                    <xs:element name="ItemCode" minOccurs="0" type="xs:string"/>
                    <xs:element name="ItemName" minOccurs="0" type="xs:string"/>
                    <xs:element name="LastPurPrc" minOccurs="0" type="xs:decimal"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:complexType>

    </xs:element>
    </xs:schema>
    -<Table>
         <ItemCode>0004</ItemCode>
         <ItemName>Realisierung FP</ItemName>
         <LastPurPrc>0.000000</LastPurPrc>
    </Table>
    -<Table>
         <ItemCode>0005</ItemCode>
         <ItemName>km-Geld</ItemName>
         <LastPurPrc>0.000000</LastPurPrc>
     </Table>
</oitm>

0 个答案:

没有答案