我从以下位置获取了一个simplexml对象:
$xml = simplexml_load_string($data);
如果我做dd($xml)
,则会在控制台中得到以下字符串:
SimpleXMLElement {#232
+"Data": SimpleXMLElement {#240}
+"Error": SimpleXMLElement {#241}
+"xmlData": "<root><row><FiscalCode>27221245</FiscalCode><CompanyName>Nume Companie SRL</CompanyName><LegalForm>SRL</LegalForm><RegistrationNumber>J40/111/2010</RegistrationNumber><DateOfIncorporation>2010-07-29</DateOfIncorporation><Status>functiune;</Status><ShareCapital>1.510000000000000e+005</ShareCapital><NACE>6201</NACE><NACE_Descr>Activităţi de realizare a soft-ului la comandă (software orientat client)</NACE_Descr><PrimaryActivityVersion>2</PrimaryActivityVersion><NumberOfemployees>20</NumberOfemployees><County>Municipiul Bucuresti</County><City>BUCURESTI SECTORUL 5</City><Street>DR. JOSEPH LISTER</Street><Number>22</Number><Block /><Entrance /><Floor /><Apartment>1</Apartment><PostalCode>50543</PostalCode><PhoneNumber>0724063943</PhoneNumber><E-mail /><Web /><OwnershipForm /><CompanyIdentification>certificat de înmatriculare preschimbat; </CompanyIdentification><UpdateOn>2018-07-04</UpdateOn><Headquarters_DocumentType>Contract de închiriere</Headquarters_DocumentType><Headquarters_DocumentDuringType>Temporar</Headquarters_DocumentDuringType><Headquarters_DocumentNumber>1</Headquarters_DocumentNumber><Headquarters_DocumentDate>01-11-2016</Headquarters_DocumentDate><HeadquartersExpiryDayFrom>2016-11-01</HeadquartersExpiryDayFrom><HeadquartersExpiryDayUntil>2019-11-01</HeadquartersExpiryDayUntil><DateofIncorporationDocument>2018-07-03</DateofIncorporationDocument><SecondaryHeadquarters><row><Name>Punct de lucru</Name><StartDate /><StopDate /><Country>ROMANIA</Country><Locality>BUCUREŞTI SECTORUL 5</Locality><Street>DR. STAICOVICI</Street><Number>19</Number><Block /><Entrance /><Floor>1</Floor><Apartment>2</Apartment><District>5</District><PostalCode /></row><row><Name>PUNCT DE LUCRU</Name><StartDate>2013-05-01 00:00:00.0000000</StartDate><StopDate>2014-05-01 00:00:00.0000000</StopDate><Country>ROMANIA</Country><Locality>BUCUREŞTI SECTORUL 5</Locality><Street>B-dul EROILOR</Street><Number>13</Number><Block /><Entrance /><Floor /><Apartment>2</Apartment><District>5</District><PostalCode /></row></SecondaryHeadquarters></row></root>"
}
提取 FiscalCode
的正确方法我提到
dd($xml->FiscalCode)
不返回任何内容。
还
dd($xml->root->row->FiscalCode);
不起作用
原始xml是从外部链接获取的:
看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<Result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Data>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded" />
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" />
</Data>
<Error />
<xmlData><root><row><FiscalCode>27225145</FiscalCode><CompanyName>Nume Companie SRL</CompanyName><LegalForm>SRL</LegalForm><RegistrationNumber>J40/7213/2010</RegistrationNumber><DateOfIncorporation>2010-07-29</DateOfIncorporation><Status>functiune;</Status><ShareCapital>1.510000000000000e+005</ShareCapital><NACE>6201</NACE><NACE_Descr>Activităţi de realizare a soft-ului la comandă (software orientat client)</NACE_Descr><PrimaryActivityVersion>2</PrimaryActivityVersion><NumberOfemployees>20</NumberOfemployees><County>Municipiul Bucuresti</County><City>BUCURESTI SECTORUL 5</City><Street>DR. JOSEPH LISTER</Street><Number>22</Number><Block /><Entrance /><Floor /><Apartment>1</Apartment><PostalCode>50543</PostalCode><PhoneNumber>0724063943</PhoneNumber><E-mail /><Web /><OwnershipForm /><CompanyIdentification>certificat de înmatriculare preschimbat; </CompanyIdentification><UpdateOn>2018-07-04</UpdateOn><Headquarters_DocumentType>Contract de închiriere</Headquarters_DocumentType><Headquarters_DocumentDuringType>Temporar</Headquarters_DocumentDuringType><Headquarters_DocumentNumber>1</Headquarters_DocumentNumber><Headquarters_DocumentDate>01-11-2016</Headquarters_DocumentDate><HeadquartersExpiryDayFrom>2016-11-01</HeadquartersExpiryDayFrom><HeadquartersExpiryDayUntil>2019-11-01</HeadquartersExpiryDayUntil><DateofIncorporationDocument>2018-07-03</DateofIncorporationDocument><SecondaryHeadquarters><row><Name>Punct de lucru</Name><StartDate /><StopDate /><Country>ROMANIA</Country><Locality>BUCUREŞTI SECTORUL 5</Locality><Street>DR. STAICOVICI</Street><Number>19</Number><Block /><Entrance /><Floor>1</Floor><Apartment>2</Apartment><District>5</District><PostalCode /></row><row><Name>PUNCT DE LUCRU</Name><StartDate>2013-05-01 00:00:00.0000000</StartDate><StopDate>2014-05-01 00:00:00.0000000</StopDate><Country>ROMANIA</Country><Locality>BUCUREŞTI SECTORUL 5</Locality><Street>B-dul EROILOR</Street><Number>13</Number><Block /><Entrance /><Floor /><Apartment>2</Apartment><District>5</District><PostalCode /></row></SecondaryHeadquarters></row></root></xmlData>
</Result>
我得到这样的链接:
$curl = curl_init();
curl_setopt_array($curl, Array(
CURLOPT_URL => 'https://wsprokolekt.rocomp.ro/service.asmx/CompanyGeneralInformation?idUser=*****&CUI=******',
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_ENCODING => 'UTF-8'
));
$data = curl_exec($curl);
$xml = simplexml_load_string($data);
谢谢您的时间!
答案 0 :(得分:1)
首先,读取和解码xmlData,然后获取FiscalCode
$xml = simplexml_load_string($str);
$xml1 = simplexml_load_string(html_entity_decode($xml->xmlData));
echo $xml1->row->FiscalCode;