简体   繁体   中英

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. I have been looking into Ajax and Jquery but am really confused. 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. After sending the page to the server read all elements and create a XML document.

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.

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. Reading data can also be done with 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. 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.

    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 . It generates HTML and JavaScript based on an xsd and submits XML compliant with the xsd.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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