Comments (16)
@HKandulla I just wanted to let you know that I am having the exact same use case as you had. PR #39 saved me from having to build it myself, great work 👍
from soap-client.
Can you provide some additional information about what you are trying to do?
Maybe a code sample would be handy :)
from soap-client.
Sure. The Service I send my requests to allows me to send:
- ns1:DoNotCalltrue</ns1:DoNotCall>
- leave it out completely.
But I am not allowed to send a null value in the form: - <ns1:DoNotCall xsi:nil="true“/>
So my idea was to create a TypeConverter that checks that the provided value is null and creates no tag for that property.
from soap-client.
This can be done with a type converter, but then you'll have to add a converter for every type you want to convert this way. In this case: ns1:DoNotCall.
Another option would be a custom middleware that parses the XML and adds the nil attribute wherever you want it. You can probably do this easily by using an xpath expression.
from soap-client.
first of all, tahnks for your quick response!
I created the type converter and defined:
`
public function convertPhpToXml($php)
{
return !is_null($php)
?
sprintf('<%1$s>%2$s</%1$s>', $this->getTypeName(), $php)
:
''
;
}
`
But the generated XML still contains <ns1:CustomerID/>
Any idea how I can eliminate the creation of the tag completely?
Thanks, Hannes
from soap-client.
Hi @veewee,
I figured that the type converter only allows to alter the content and not the tag itself. But I solved it by creating a middleware that removes all empty tags:
`
public function beforeRequest(callable $handler, RequestInterface $request, array $options)
{
$xml = SoapXml::fromStream($request->getBody());
// remove all empty nodes
while (($notNodes = $xml->xpath('//*[not(node())]')) && ($notNodes->length)) {
foreach($notNodes as $node) {
$node->parentNode->removeChild($node);
}
}
return $handler(new Request(
$request->getMethod(),
$request->getUri(),
$request->getHeaders(),
$xml->toStream()
), $options);
}
`
Thanks for your help and a great library.
Best, Hannes
from soap-client.
No problem! Do you mind adding the Middleware to the package? I am pretty sure it will come in handy for other people as well. Since you already have the code, you'll only have to add some tests and some documentation.
Also, this might be a bit shorter then creating a new request manually:
$request = $request->withBody($xml->toStream());
Thanks!
from soap-client.
sure, I am happy to contribute!
I prepare a PR later tonight.
And thanks for the improvement.
Best, Hannes
from soap-client.
Hi @veewee, just to let you know, I havn't forgotten about this. As soon as I have a little time to write the tests, I create a PR. Best, Hannes
from soap-client.
Super, take all the time you need :)
from soap-client.
Feedback @HKandulla
I am still busy with the tests on #34. I want to add proper tests that make sure that even nodes with empty child nodes are removed by my middleware. But I definetely do this this week..
from soap-client.
Hi @veewee, finally the PR #39
Best, Hannes
from soap-client.
Fixed in #39.
from soap-client.
@Pton Thanks:-)
from soap-client.
@HKandulla 💯 soap is great now :D
from soap-client.
@ro0NL Thanks, glad I could contribute a little.
from soap-client.
Related Issues (20)
- Automatic generated types from wsdl HOT 2
- Providing a path to file for wizard gives invalid scheme error HOT 3
- Using GuzzleHttp with the plugin HOT 5
- Typed property ... must not be accessed before initialization HOT 4
- Soap Attachments HOT 2
- Set null as a default value for nullable properties HOT 5
- Issue when I'm trying to execute the wizzard - error of Allowed memory. Size HOT 5
- Problem to understand how to access the respons element HOT 10
- [Question] Is there a way to configure xmlns:SOAP-ENV? HOT 2
- customize clientfactory creation config HOT 3
- Generator doesn't initialise nullable values resulting in crash on access HOT 2
- Response object is not populated correctly HOT 8
- Can't instantiate custom type for GUIDs HOT 3
- Unable to handle "import" in wsdl HOT 3
- Support for complexType with sequnce of any HOT 6
- Explicitly specifying a type HOT 10
- Using different bindings HOT 1
- Using classes that extends another HOT 3
- I am getting SOAP-ERROR: Encoding: object has no 'mapped' property HOT 1
- Date xsi:type HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from soap-client.