0

在 WS 开发的上下文中,我使用以下模式:

<xs:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:Apporteurs">
  <xs:complexType name="namedValue_t">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="name" type="xs:string" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <xs:complexType name="Prospect">
    <xs:sequence>
      <xs:element name="values" type="namedValue_t" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="origine"     type="xs:string" />
    <xs:attribute name="prenom"      type="xs:string" />
    <xs:attribute name="nom"         type="xs:string" />
    <xs:attribute name="departement" type="xs:int" />
  </xs:complexType>
</xs:schema>

此架构的有效 XML 是:

<?xml version="1.0"?>
<prospect
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="WS.xsd"
   origine     = "toto"
   prenom      = "Aubin"
   nom         = "MAHE"
   departement = "33">
   <values name="Prénom">Aubin</values>
   <values name="Nom">MAHE</values>
</prospect>

如何将此 XML 值编码为 PHP 文字?

我尝试以下操作,但我不确定,因为服务器无法处理使用此数据构建的 WS 请求:

$prospect = array(
   'origine'     => 'test-origine',
   'prenom'      => 'Aubin',
   'nom'         => 'MAHE',
   'departement' => 33,
   'values'      => array());
$prospect['values'][] = array( 'name' => 'Prénom', 'value' => 'Aubin' );
$prospect['values'][] = array( 'name' => 'Nom'   , 'value' => 'MAHE'  );

当最后两行被注释时,请求成功执行。

4

1 回答 1

0

多亏了这个答案,WS Client 变成了:

<?php
ini_set( 'soap.wsdl_cache_enabled', '0' );
ini_set( 'display_errors'         , '1' );

$prospect = array(
    'origine'     => 'test-origine',
    'prenom'      => 'test prenom',
    'nom'         => 'test nom',
    'departement' => 33,
    'values'      => array(
        (object)array( 'name' => 'prenom', 'value' => 'Aubin' ),
        (object)array( 'name' => 'nom'   , 'value' => 'MAHE'  ),
    )
);

$lfinance = new SoapClient( 'http://xxxxxxxxxxxxx/Apporteurs.wsdl' );
$lfinance->AjouterUnProspect( $prospect );
?>
于 2013-11-06T00:13:25.093 回答