Zipper for creating xml requests?
Asked Answered
P

3

47

How can one create an XML request conforming to an XSD such that the request is valid?

One way would be to create the whole request and then verify it on the XSD. Is there a way to create a request while walking the schema?

The first thought that came to mind was of Zipper, but I am really not sure if they can be used here.

Maybe I have not understood it well, but it seems Zipper's are great if there is already some structure defined and things need to be changed in that structure. Can Zipper be used for a changing structure? (E.g Appending a sequence to an array of sequence ?)

Perfecto answered 24/1, 2014 at 1:26 Comment(7)
I am inclined to have better data structure and serialize good xml rather than validating XML afterwards. But if you can add some code, and idea about how zippers can be used, it'd help.Tecla
Have a look at HaXML package. It has XsdToHaskell to create haskell code from XSD schema. Not exactly what you are asking, but might help.Tecla
@YogeshSajanikar Akshat isn't asking for how to validate, but rather whether it's possible to generate valid XML directly whilst walking an XSD. This would presumably take a zipper and walk it a bit like scan walks a list, outputting stuff as it goes.Neoma
I think this is a great question. Deep thinking here.Neoma
@chunksOf50, agree! How about using QuickCheck.Arbitrary or something similar to create conforming XML. Each traversal can create an conforming XML. In fact, we can use HaXML approach to create the instances of Arbitrary as well, and then create whole XML in one go!Tecla
@YogeshSajanikar But that would generate random XML. I think the idea is to generate valid but purposeful XML, where it's guaranteed to be valid because you're walking the XSD.Neoma
@enoughreptocomment That's like trying to create meaningful strings by walking the regex. It doesn't work that way.Thorma
B
1

As Tomalak said in a comment,

That's like trying to create meaningful strings by walking the regex. It doesn't work that way.

A zipper helps you take a meandering walk through a structure, inspecting parts and optionally modifying them; in the end, you have the option of "zipping up" the zipper to get a modified version of the original. There are at least two major problems with your idea:

  1. The structure of an XSD is not the same as, or even terribly similar to, the structure of the documents it encodes. If you were to use a zipper to modify an XSD so as to produce XML valid according to that XSD, you will end up restructuring it completely, and the type system will not help you get this right.

  2. A zipper is a way of focusing on part of some data structure. Before you think too hard about the zipper, you should think about what data structure you're unzipping. Depending on what you're doing, you may or may not find it useful to use a zipper, but the zipper and its invariants will always relate back to the structure and its invariants.

Bridge answered 11/2, 2015 at 23:3 Comment(0)
B
0

Once had the occasion to test this tool: camprocessor It did actually work and produce valid XML files that you could customize with data from databases.

There is some guidance on this at OASIS

Barner answered 13/2, 2015 at 23:13 Comment(0)
D
-1

Create an XMLHttpRequest Object

All modern browsers (IE7+, Firefox, Chrome, Safari, and Opera) have a built-in XMLHttpRequest object.

Syntax for creating an XMLHttpRequest object:

xmlhttp=new XMLHttpRequest();
Devisal answered 20/2, 2015 at 7:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.