doubianxian6557 2010-07-27 10:40
浏览 67
已采纳

如何减少SOAP响应中的字节数?

is there a way to reduce the number of bytes sent to the network from a SOAP response? I use nuSoap in PHP and would like to avoid xsi:type="xsd:string", xsi:type="xsd:int" in every node. Is there a way to do it?

Thanks in advance c.

  • 写回答

3条回答 默认 最新

  • duancheng3342 2010-08-02 08:40
    关注

    If you are strictly tied to sending valid SOAP response back to Flash client, and if using valid schema is not an option (which would simplify output markup), then no, you can't do anything about it...

    However, if you're NOT tied to sending valid SOAP response, and your developer really insists on getting non-verbose markup, then you are left with an alternative of rolling your own. If this is the case, read on.

    You can use some of existing XML Serializer classes available via PEAR, or some other source. If you wanted to go down the Trully-Roll-Your-Own route, there are PHP classes to aid you in creating valid XML directly.

    Not to repeat what's being said elsewhere, here's in-depth example about how to serialize some data using PEAR XML_Serializer.

    Another really simple example, this time it's SimpleXML-based, where you add child elements and attributes as needed to meet desired output.

    $xml = new SimpleXMLElement('<?xml version="1.0" standalone="yes"?>');
    $ch1 = $xml->addChild("root");
    $ch2 = $ch1->addChild("element");
    // you obviously have no use for attributes, but I included it for completeness
    $ch2->addAttribute("foo", "bar");
    $ch2->addChild("subElement", "value1");
    
    $outxml = $xml->asXML();
    

    Code above would produce something like:

    <?xml version="1.0" standalone="yes"?>
    <root>
        <element foo="bar">
             <subElement>value1</subElement>
        </element>
    </root>
    

    I hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?