我有以下代码从第三方读取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 :(得分: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;
}
希望这有助于那些对选项感到好奇的人解决问题。