Невозможно прочитать XML из вызова API

У меня есть следующий код для чтения XML-данных от третьих лиц

$supplier_response = getsupplierresponse($argument1);
$resultxml = simplexml_load_string($supplier_response);
$test = getXMLNode($resultxml, "FormattedName");
var_dump($test); //no result

function getXMLNode($xmlobj, $path, $nodenumber=0){
return $xmlobj->getElementsByTagName($path)->item(0)->childNodes->item($nodenumber)->nodeValue;
}

Если я читаю тот же xml из локального файла, код работает, и [var_dump ($ test);] дает правильный результат. Что конкретно делается, если мы извлекаем XML из стороннего сервиса для чтения данных?

Вот XML, который я получил, вызывая стороннюю службу.

<?xml version="1.0" encoding="utf-8"?>
<Resume lang="fr" src="xxx-CVX schema:2.0.29 release:0.23.1.52647 rdate:2017-11-01">
<StructuredXMLResume>
<ContactInfo>
<PersonName id="2">
<FormattedName>Boris Becker</FormattedName>
<GivenName>Boris</GivenName>
<FamilyName>Becker</FamilyName>
</PersonName>
<ContactMethod>
<Mobile id="4">
<InternationalCountryCode>33</InternationalCountryCode>
<SubscriberNumber>777777777</SubscriberNumber>
<FormattedNumber>+33 777777777</FormattedNumber>
</Mobile>

<PostalAddress id="3" type="main">
<CountryCode>FR</CountryCode>
<Municipality>Paris</Municipality>

</PostalAddress>
</ContactMethod>
</ContactInfo><RevisionDate id="1">2018-02-22</RevisionDate>
</StructuredXMLResume>
<NonXMLResume>

<TextResume>

<span inprof="n" id="1" class="date">{{DOCUMENT_DATESTAMP}} 2018-02-22 {{END_DOCUMENT_DATESTAMP}}</span>

<span inprof="y" id="2" class="nominal">Boris Becker</span>
<span inprof="y" id="3" class="location">Paris</span>
<span inprof="y" id="4" class="telephone">0777777777</span>

</TextResume>

</NonXMLResume><UserArea>
<xResumeUserArea>
<AdditionalPersonalData>
<ExperienceSummary>
<ExecutiveBrief>Boris Becker is a resident of Paris, France. He has a track record with no real experience.</ExecutiveBrief>
</ExperienceSummary>
</AdditionalPersonalData>
<ParserInfo>
<ParserConfiguration>{max_len=50000} {tel_flag=} {send_zip=} {fast_conv=} {DEF_LOCAL=} {sdate=0} {no_email_body=0} {do_clever_zoning=0} {keep_zone_span=0} {keep_span=1} {complex=0} {accept_langs=} {not_accept_langs=} {prefer_lang_cv=} {pers_only=0} {projects_off=0}
{tree_search_on=0} {all_skills=0} {turbo=0} {split_language=0} {picture=0} {picture_inline=0} {debug=0} {ocr_allowed=1} {name_space=0} {charset=} {hrxml_upgrade_edu_hist=0}{hrxml_add_languages_section=1}{spool=} {docID=} {user=nottx02} </ParserConfiguration>
<ParserRelease>0.23.1.52647</ParserRelease>
<ParserReleaseDate>2017-11-01</ParserReleaseDate>
<ParserSchema>2.0.29</ParserSchema>
<ParserSchemaLocation>http://cvxdemo.daxtra.com/cvx/cvx_schema/candidate/2.0.29/Resume.xsd</ParserSchemaLocation>
<ConverterRelease>0.16.2.53041</ConverterRelease>
<ConverterReleaseDate>2017-12-07</ConverterReleaseDate>
</ParserInfo>
<FileStruct filename="/tmp/soap_617785094628694">

<attachment fname="0439984814400614" ftype="docx" conv="yes" doc_type="cv" lang="">/tmp/soap_617785094628694</attachment>

</FileStruct>
</xResumeUserArea>
</UserArea>
<preserveWhiteSpace></preserveWhiteSpace>
<formatOutput>1</formatOutput>
</Resume>

0

Решение

Единственный способ исправить это — сохранить локально и прочитать его снова. Я не уверен, что это идеальный ответ, но что-то сработало для меня. XML становится читаемым, вызывая функцию ниже.

function cleanse_supplier_response($supplier_response){
$result = simplexml_load_string($supplier_response);
$xml_string = $result->saveXML();
$thisxml_object = new DOMDocument();
$thisxml_object->loadXML($xml_string);
return $thisxml_object;
}

Надеюсь, что это поможет тем, кому интересно, как решить проблему.

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]