目前,我正在尝试自动为MS SQL2005 Server的所有SQL作业生成一个创建脚本。
有谁知道一个好的TSQL语句或一个简单的程序吗?
目前我遇到了从具有重复元素的xsd生成类文件的问题.我在VS2005 SP1中使用自定义工具'MsDatasetGenerator',从xsd为c#创建一个类型化数据集.我试图通过这个模式解析xml
<?xml version="1.0" encoding=\"utf-8\"?>
<xs:schema id="XSDobject" targetNamespace="http://tempuri.org/XSDobject.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XSDobject.xsd" xmlns:mstns="http://tempuri.org/XSDobject.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="order">
<xs:complexType>
<xs:sequence>
<xs:element name="contact">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="phone" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="buyer">
<xs:complexType>
<xs:sequence>
<xs:element name="contact">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="phone" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
但我得到以下错误" 同一个表'联系'不能是两个嵌套关系中的子表."
XSD正确编译,但它是无法处理重复表的类型化数据集.现在我也测试了xsd.exe工具,但它似乎生成与msdatasetgenerator相同的代码.我还尝试了一些第三方代码生成器工具,如XSD2Code,CodeXS,AltovaXmlSpy,但我也无法使用嵌套元素.
或者,我可以在输入和输出处解决xslt转换的问题但是它会花费我很多性能.
所以现在我问是否有人可以帮助我为VS2005提供一个好的解决方案,或者知道可以解决这个问题的好的xsd类生成器.它不必是类型化的数据集,如果它作为数组或列表工作,它也是完美的,只要它很容易序列化和反序列化.
在此先感谢Freggel
我正在尝试将日期时间转换为日期格式yyyy-MM-dd,因为我使用的是xsd.exe工具,xs:date数据类型会自动更改为datetime数据类型,因为.NET中没有类型完全匹配类型xs:date的框架.
但我无法让它发挥作用
<articles>
<article>
<articleid>48992</articleid>
<deliverydateasked>2009-01-29T00:00:00+01:00</deliverydateasked>
</article>
<article>
<articleid>48993</articleid>
<deliverydateasked>2009-01-30T00:00:00+01:00</deliverydateasked>
</article>
</articles>
Run Code Online (Sandbox Code Playgroud)
试图将xml转换为
<articles>
<article>
<articleid>48992</articleid>
<deliverydateasked>2009-01-29</deliverydateasked>
</article>
<article>
<articleid>48993</articleid>
<deliverydateasked>2009-01-30</deliverydateasked>
</article>
</articles>
Run Code Online (Sandbox Code Playgroud)
目前我正在使用这个XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<articles>
<xsl:apply-templates select="article">
</xsl:apply-templates>
</articles>
</xsl:template>
<xsl:template name="FormatDate">
<xsl:param name="DateTime" />
<xsl:variable name="date">
<xsl:value-of select="substring-before($DateTime,'T')" />
</xsl:variable>
<xsl:if test="string-length($date) != 10">
<xsl:value-of select="$DateTime"/>
</xsl:if>
<xsl:if test="string-length($date) = 10">
<xsl:value-of select="$date"/>
</xsl:if>
</xsl:template>
<xsl:template match="article">
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="deliverydateasked"/>
</xsl:call-template>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
有谁知道一个很好的xslt转换.
提前致谢
我的代码的输出结果是
<articles />
Run Code Online (Sandbox Code Playgroud)