简体   繁体   English

从XSD创建Web表单,然后输出xml表单

[英]create web form from XSD and then output xml form

I am creating a tool that allows someone to input recipes which should then be saved as an XML file, I have created my XSD but I was wondering how I can make a form on my web page that will allow the user to enter their recipe and adhere to the schema. 我正在创建一个工具,允许某人输入食谱,然后将其保存为XML文件,我创建了我的XSD,但我想知道如何在我的网页上创建一个表单,允许用户输入他们的食谱和坚持架构。 I have been looking into Ajax and Jquery but am really confused. 我一直在研究Ajax和Jquery,但我真的很困惑。 Any help would be much appreciated! 任何帮助将非常感激!

Nick 缺口

Your information is a bit minimal. 您的信息有点小。 So if I'm stating the obvious my apologes. 所以,如果我说明了我明显的抱怨。 The basic approach would be to create a page that implements all your data elements. 基本方法是创建一个实现所有数据元素的页面。 Use javascript/Jquery to validate requiered elements. 使用javascript / Jquery验证所需的元素。 After sending the page to the server read all elements and create a XML document. 将页面发送到服务器后,读取所有元素并创建XML文档。

You didn't specify your server handling language, but this approach can be used with any of the known languages such as PHP, C#, VB.NET, Ruby, Perl. 您没有指定服务器处理语言,但此方法可以与任何已知语言一起使用,例如PHP,C#,VB.NET,Ruby,Perl。

Depending on your choice creating and maintaining the template code of the page is less or more work. 根据您的选择,创建和维护页面的模板代码的工作量越来越少。 You could also use XSLT to generate a HTML page from the XSD. 您还可以使用XSLT从XSD生成HTML页面。 Reading data can also be done with XSLT. 读取数据也可以使用XSLT完成。 If you use the Smalltalk web application framework Seaside, pages are generated from code, so there is only one place to maintain your application. 如果您使用Smalltalk Web应用程序框架Seaside,页面是从代码生成的,因此只有一个地方可以维护您的应用程序。 But that is not really widely used so that might not be an option. 但这并没有被广泛使用,因此可能不是一种选择。 Most other languages use templates for pages. 大多数其他语言使用页面模板。

You can do that by the following code: The following code check if file not exists then create xml if not then load the created xml file. 您可以通过以下代码执行此操作:以下代码检查文件是否不存在,然后创建xml,如果没有,则加载创建的xml文件。

    string file = MapPath("~/Recepies.xml");

    XDocument doc;

    //Verify whether a file is exists or not
    if (!System.IO.File.Exists(file))
    {
        doc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"),
            new System.Xml.Linq.XElement("Recepies"));
    }
    else
    {
        doc = XDocument.Load(file);
    }

    XElement ele = new XElement("Recepie", txtRecepie.Text.Trim());
    doc.Root.Add(ele);
    doc.Save(file);

    using (StreamWriter writer = new StreamWriter(Response.OutputStream, new UTF8Encoding(false)))
    {
        doc.Save(writer);
        Response.ContentType = "text/xml";
        Response.AddHeader("Content-disposition", "attachment;filename=file.xml");
        Response.Flush();
        Response.End();
    }

Try the tool http://github.com/davidmoten/xsd-forms . 试试http://github.com/davidmoten/xsd-forms这个工具。 It generates HTML and JavaScript based on an xsd and submits XML compliant with the xsd. 它基于xsd生成HTML和JavaScript,并提交符合xsd的XML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM