I have several types of XML document.
The format of (i.e. the elements in) each document type is defined in an XSD.
Is there a convenient way to create HTML elements (or ASP.NET controls) on an ASP.NET form, to display/edit the elements in (contents of) an XML document, given the XML document and/or the document's XSD definition as input?
Within the XML/XSD:
- Complex (i.e. parent) elements may contain sub-elements
- Simple elements are of type 'string', 'integer', 'list of string values', etc.: which should map to corresponding HTML input elements
- Elements are documented (labelled) using
<xs:annotation>
in the XSD (these would be suitable HTML<label>
elements for the corresponding<input>
elements). - Each element is required, not required, and/or there may be several of them, specified using
minOccurs
andmaxOccurs
in the XSD
As well as generating the ASP.NET form, when the user posts the completed form, the software should read the returned data and pack it into an XML document.
How to do this?
I can write software to parse the XSD and generate the forms myself but that seems like a lot of code to write in-house and maintain.
-
Do you have an XSLT or an XML schema (XSD)?Wyatt Barnett– Wyatt Barnett2014年01月22日 15:34:45 +00:00Commented Jan 22, 2014 at 15:34
-
@WyattBarnett I have an XSD. Thanks for the correction.ChrisW– ChrisW2014年01月22日 15:39:18 +00:00Commented Jan 22, 2014 at 15:39
-
If you were that way inclined you could probably write some kind of XSLT to convert the XSD into an ASP.Net page. Wouldn't surprise me if someone's done it already... :)James Snell– James Snell2014年01月22日 17:31:33 +00:00Commented Jan 22, 2014 at 17:31
-
@RobertHarvey I see only "The member requested was not found." from that URL. Do you know the name of the project or title of the article you were referring to?ChrisW– ChrisW2014年01月22日 22:02:27 +00:00Commented Jan 22, 2014 at 22:02
-
Ack. Apparently you need the descriptive part of the URL on CodeProject, or it won't work: codeproject.com/Articles/38277/…Robert Harvey– Robert Harvey2014年01月22日 22:12:44 +00:00Commented Jan 22, 2014 at 22:12
1 Answer 1
There isn't a direct way that I'm aware of off the top of my head. But XSD to form was hawt back in 2001 when .NET was conceived so you can likely use tools like xsd.exe to generate a class from that. Then you should be able to use the EditorFor in ASP.NET to generate a form for that. Or any other form generator that takes classes as input.
-
xsd2code is a similar utility that will generate a class for you that you can then use in conjunction with EditorFor, although EditorFor may only be applicable to ASP.NET MVC. Not sure it EditorFor is applicable to WebForms. Which are you using?maelstrom– maelstrom2014年01月22日 20:39:25 +00:00Commented Jan 22, 2014 at 20:39
-
Thanks for the hint. I don't know yet whether I'll go this route. I found many alternatives to xsd.exe at stackoverflow.com/questions/386155/…ChrisW– ChrisW2014年01月23日 03:33:01 +00:00Commented Jan 23, 2014 at 3:33