droyo / go-xml

utility and code-generation libraries for XML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SOAP multirefs

droyo opened this issue · comments

Let's talk about the elephant in the room: references in SOAP documents. We can generate the greatest type declarations ever, but that won't do us any good in the face of documents such as this:

<Body>
  <multiRef id="obj0" soapenc:root="0" xsi:type="myNS:Part">
    <sku>SJ-47</sku>
  </multiRef>

  <response>
    <arg href="#obj0"/>
  </response>
</Body>

ugh. What's worse, one of the explicit reasons listed in the SOAP spec for references is to support data models that include loops. A loop would cause some problems if we simply tried to flatten a document.

A long time ago I wrote a tiny package that took the "flattening" approach: aqwari.net/exp/soap. That's one approach.

  • Should I bundle flattening code with the generated code for wsdlgen? Seems a little heavy.
  • Make a package to handle the references? I like that today, code generated by xsdgen and wsdlgen has no dependencies outside of the stdlib.

What I am leaning towards is developing a standalone package that users can choose to add to their generated packages if they know they're going to be dealing with references. Something that wraps an xml.Decoder and decodes a document as if it were flattened (while still handling loops in a sane way if possible). That package should have more stringent release engineering/compatibility guarantees, since it will be imported in users' code. But I haven't started this package, so I'm keeping an issue here so I don't forget.

Hi,
This is a great package! Unfortunately I need to parse messages with multirefs. Do you have any updates on this issue?

I started work on the multiref branch, but unfortunately I am not close to resolving this issue, and will have limited time to make progress for the next month or so.

If your inputs do not contain loops, you cloud get this package to work using the "flattening" approach:

  • Read the whole input into a []byte
  • Use a package like aqwari.net/exp/soap to replace any multi refs with their content, or write your own routine to do this.
  • Turn the []byte back into an io.Reader using bytes.NewReader or similar and pretend nothing ever happened :)

The flattening approach works great. Thank!
Hope to see the the support for multiref added.