SOAP::Data::Builder,删除 xsi:nil="true";当没有提供值时 [英] SOAP::Data::Builder, remove xsi:nil="true" when no value provided

查看:24
本文介绍了SOAP::Data::Builder,删除 xsi:nil="true";当没有提供值时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我写这个 SOAP::Data::Builder 代码(其中 $sb 是一个 SOAP::Data::Builder 对象)

If I write this SOAP::Data::Builder code (where $sb is a SOAP::Data::Builder Object)

    $sb->add_elem(
        attributes => { run => 'true' },
        name       => 'ccAuthService',
#       value      => ' ', # hack to prevent cs side unparseable xml
    );

它生成以下内容

<ccAuthService xsi:nil="true" run="true" />

这是不可接受的,因为 xsi:nil 会导致接收端出现问题.但是,如果我取消注释注释掉的行,我会得到

Which is unacceptable because the xsi:nil causes problems on the the receiving end. However if I uncomment the commented out line, I get

<ccAuthService run="true"> </ccAuthService>

从技术上讲,这是可行的,因此这是一种解决方法.但我最终想要的是

Technically this works, so it's a workaround. But what I'd like to ultimately have is

<ccAuthService run="true" />

我知道哪些有效,但我不知道如何生成它.

Which I know works, I just can't figure out how to have it generated.

推荐答案

这是使用 SOAP::Lite(SOAP::Data::Builder 使用的)解决此问题的解决方案.

This is a solution for fixing this issue with SOAP::Lite (which SOAP::Data::Builder uses).

在代码中的某处定义以下内容:

Define the following somewhere in your code:

sub SOAP::Serializer::as_nonil
{
    my ($self, $value, $name, $type, $attr) = @_;
    delete $attr->{'xsi:nil'};
    return [ $name, $attr, $value ];
}

要使用这种类型:

SOAP::Data->new(
   type => 'nonil',
   name => 'ping',
   prefix => '',
   uri => 'http://myschema.domain/',
);

关于此的一些提示在 SOAP::序列化器.

Some hints on this are in SOAP::Serializer.

这篇关于SOAP::Data::Builder,删除 xsi:nil="true";当没有提供值时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆