0

I am trying to validate an xml which I get from the users. I propose a list of parameters (which may change every now and then) in an xml format with empty values. Users should fill in values and upload it. Then I should validate the uploaded xml and save the values in db(Mongodb).

I tried trang to generate xsd from an xml file. It works but I do not know how to specify that user can leave some of these parameters without values.

I read something about nillable =true or minoccurs=0 which is used in xsd, however, I don’t want to modify the generated xsd manually. Is there a better solution? If it is not possible with trang, which converter do you suggest?(I am using java)

  • are you looking for this? http://stackoverflow.com/a/9243789/3377857 – Klemens Morbe Mar 18 '14 at 18:31
  • not really. In this link, it shows how to change xsd to make an element optional. However, I prefer not to change it manually since I generate xsd using trang. My question is if it is possible in trang or other converters? –  Mar 18 '14 at 18:37

1 Answers1

0

Using trang to set xml element optional:

You don't. To make that work properly you would need the "read my mind" instruction.

trang allows you to set the bulk content of the xsd. The resulting xsd should be tweaked by you to properly encode your business logic. That is; use trang to get the bulk boilerplate done. Edit to get the details that trang can not possibly know into the xsd.

You said:

I propose a list of parameters (which may change every now and then) in an xml format with empty values.

The xsd better well match that list of parameters. If you update the parameters, update the xsd.

I have used trang myself. my recommended steps:

  1. Use trang on your template and user output.

  2. Edit resulting xsd by hand or with editors such as "XML Copy editor".

  3. Verify it works against the body of user input, edit as needed. (create unit tests.)

  4. If parameter change, edit xsd to as needed. If big parameter change, use subsets of trang's output to modify the xsd.

If your parameters do not change- the xsd does not change. If you are changing the xsd for each user input... you are doing it wrong.