How to generate XML in the SOAP in PHP?

You need to register the XML SOAP request in the following form:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://aisws.ingos.ru/services/b2b/sales/agents/1.0/">
<soapenv:Header/>
<soapenv:Body>
<ns:GetTariffRequest>
<NeedList>1</NeedList>

<SessionToken>FA7ADGQXElGe8AQKWN0A0AWP5/626NAA6AXv</SessionToken>

<TariffParameters>
<Agreement>
<General>
<Product>753518300</Product>
<DateBeg>2018-09-06T00:00:00</DateBeg>
<DateEnd>2019-09-05</DateEnd>
<CitySales>77000000000</CitySales>
<Individual>N</Individual>
</General>
<Insurer>
<SbjRef>1</SbjRef>
<MobilePhone>79616172222</MobilePhone>
<Email>testovtest@mail.ru</Email>
</Insurer>
<Owner>
<SbjRef>1</SbjRef>
</Owner>
<SubjectList>
 <Subject SbjKey="1">
<SbjType>F</SbjType>
<SbjResident>Y</SbjResident>
 <FullName>Tester Web Serwisowych</FullName>
<Gender>M</Gender>
<BirthDate>1987-01-01</BirthDate>
<CountryCode>643</CountryCode>
<IdentityDocument>
<DocType>30363316</DocType>
 <Serial>45 45</Serial>
<Number>545545</Number>
<DocDate>2010-01-01</DocDate>
 <DocIssuedBy>OVD Moscow</DocIssuedBy>
</IdentityDocument>
<Address>
<CountryCode>643</CountryCode>
<CityCode>77000000000</CityCode>
<StreetCode>770000000000391</StreetCode>
 <StreetName>8 March street</StreetName>
<House>155</House>
<Flat>155</Flat>
</Address>
</Subject>
</SubjectList>
</Agreement>
</TariffParameters>
</ns:GetTariffRequest>
</soapenv:Body>
</soapenv:Envelope>


The question is in the tag :
<Subject SbjKey="1">

XML form something like this, but how to add an attribute SbjKey="1", do not understand.

$connect = new stdClass();
$connect->NeedList='1';
$connect->SessionToken='4A3ADaUXNFIaQALOT55ACA3DOZ8KJTMAsauz';
$connect->TariffParameters->Agreement->General->Product='753518300';
$connect->TariffParameters->Agreement->General->DateBeg='2018-09-06T00:00:00';
$connect->TariffParameters->Agreement->General->DateEnd='2019-09-05';
$connect->TariffParameters->Agreement->General->CitySales='77000000000';
$connect->TariffParameters->Agreement->General->Individual='N';

$connect->TariffParameters->Agreement->Insurer->SbjRef='1';
$connect->TariffParameters->Agreement->Insurer->MobilePhone='79616172222';
$connect->TariffParameters->Agreement->Insurer->Email='testovtest@mail.ru';

$connect->TariffParameters->Agreement->Owner->SbjRef='1';



$connect->TariffParameters->Agreement->SubjectList->Subject->SbjType='f';
$connect->TariffParameters->Agreement->SubjectList->Subject->SbjResident='Y';
$connect->TariffParameters->Agreement->SubjectList->Subject->FullName='Tester Web Serwisowych';
$connect->TariffParameters->Agreement->SubjectList->Subject->Gender='M';
$connect->TariffParameters->Agreement->SubjectList->Subject->BirthDate='1987-01-01';
$connect->TariffParameters->Agreement->SubjectList->Subject->CountryCode='643';

$connect->TariffParameters->Agreement->SubjectList->Subject->IdentityDocument->DocType='30363316';
$connect->TariffParameters->Agreement->SubjectList->Subject->IdentityDocument->Serial='45 45';
$connect->TariffParameters->Agreement->SubjectList->Subject->IdentityDocument->Number='545545';
$connect->TariffParameters->Agreement->SubjectList->Subject->IdentityDocument->DocDate>='2010-01-01';
$connect->TariffParameters->Agreement->SubjectList->Subject->IdentityDocument->DocIssuedBy='OVD Moscow';

$connect->TariffParameters->Agreement->SubjectList->Subject->Address->CountryCode='643';
$connect->TariffParameters->Agreement->SubjectList->Subject->Address->CityCode='77000000000<';
$connect->TariffParameters->Agreement->SubjectList->Subject->Address->StreetCode='770000000000391';
$connect->TariffParameters->Agreement->SubjectList->Subject->Address->StreetName='March 8 street';
$connect->TariffParameters->Agreement->SubjectList->Subject->Address->House='155';
$connect->TariffParameters->Agreement->SubjectList->Subject->Address->Flat>='155';
March 20th 20 at 11:37
2 answers
March 20th 20 at 11:39
Solution
You will have to manually create the XML. Built-in tools for working with attributes from SoapClient not.

$xw = new XMLWriter();
$xw->openMemory();
$xw->startElementNS('ns1', 'GetTariffRequest', null);
$xw->startElement('NeedList');
$xw->text('1');
$xw->endElement();

$xw->startElement('Subject');
 $xw->writeAttribute('SbjKey', '1');
$xw->endElement();
$xw->endElement();

$s = new SoapClient(...);
$s->GetTariff(new SoapVar($xw->outputMemory(), XSD_ANYXML));

XMLWriter here only as an example. To make a string with XML you can in any other way.
March 20th 20 at 11:41

Find more questions by tags PHPSOAPWSDL