【问题标题】:Generate Xml from Xsd with ado.net使用 ado.net 从 Xsd 生成 Xml
【发布时间】:2017-10-13 09:27:37
【问题描述】:

我想从 xsd 生成 xml,这个 xml 我想包含来自 xsd 的指定属性。有什么想法吗?

string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
    string SaveLocation = Server.MapPath("Data") + "\\" + fn;
    try
    {
        File1.PostedFile.SaveAs(SaveLocation);
        Response.Write("The file has been uploaded.");
    }
    catch (Exception ex)
    {
        Response.Write("Error: " + ex.Message);
        //Note: Exception.Message returns a detailed message that describes the current exception. 
        //For security reasons, we do not recommend that you return Exception.Message to end users in 
        //production environments. It would be better to put a generic error message. 
    }
    try
    {
        XmlTextReader reader = new XmlTextReader(SaveLocation);
        //XmlSchema myschema = XmlSchema.Read(reader, ValidationCallback);
        while (reader.Read())
        {
           // LiteralURL.Text += reader.ReadString();
        }
        // Response.Write("\t"+myschema.Items);
        XDocument doc = XDocument.Load(SaveLocation);
        var ListNode = new List<XNode>();
        if (doc != null)
        {
            Response.Write("nu este null");
        }
        else
        {
            Response.Write("Null !");
        }
        int i = 0;
       string str = "";
        foreach (XNode nodes in doc.Elements())
        {

            str = "node1:  " + nodes.ToString();
            ListNode[i] = nodes;
            i++;

        }

       for(int j = 0; j < i; i++)
        {
            Response.Write("FirstNode:"+ ListNode[j]);

        }
        //Response.Write("FirstNode:" );
        Response.Write(str);
    }
    catch (Exception ex)
    {
    }

}
else
{
    Response.Write("Please select a file to upload.");
}

【问题讨论】:

标签: c# xml xsd ado.net


【解决方案1】:

看看 xsd.exe。您在 XSD 上运行它,它会为您提供基于 XSD 元素和属性的类。之后,您无需使用原始 XML 或 XSD。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 2011-08-18
    • 1970-01-01
    • 2020-11-18
    • 1970-01-01
    • 2014-10-10
    相关资源
    最近更新 更多