2016-06-08 60 views
1
$data = 
    '<parent> 
     <child> 
     <EC>1</EC> 
     <Descript>Savings Accepted</Descript> 
     <Logic>RF > LF = PAID</Logic> 
     <Rules>RF is greater than PAID and LF is equal to PAID</Rules> 
     </child> 
     <child> 
     <EC>2</EC> 
     <Descript>Savings Declined</Descript> 
     <Logic>RF >= LF < PAID</Logic> 
     <Rules>RF greater/equal PAID, LF equal PAID</Rules> 
     </child> 
    </parent>'; 

file_put_contents('rules.xml', $data); 

$xml = simplexml_load_file("rules.xml") or die("Error: Cannot create object"); 

我無法轉換。轉換xml數組在php中的數組問題

+0

$數據='儲蓄接受 RF> LF = PAID RF大於比PAID和LF等於PAID儲蓄拒絕 RF> = LF RF大於/等於PAID,LF等於PAID「; file_put_contents('rules.xml',$ data); $ xml = simplexml_load_file(「rules.xml」) 或die(「Error:Can not create object」); –

+0

請在此幫助 –

+0

您可以編輯問題,也可以刪除並創建一個新問題。請說明目前的產出和預期的產出。 – Richard

回答

0

您應該使用實體& lt;而不是<和& gt;代替>

$data = <<<'XML' 
<parent><child> 
    <EC>1</EC> 
    <Descript>Savings Accepted</Descript> 
    <Logic>RF &gt; LF = PAID</Logic> 
    <Rules>RF is greater than PAID and LF is equal to PAID</Rules> 
</child> 
<child> 
    <EC>2</EC> 
    <Descript>Savings Declined</Descript> 
    <Logic>RF &gt;= LF &lt; PAID</Logic> 
    <Rules>RF greater/equal PAID, LF equal PAID</Rules> 
</child></parent> 
XML; 
file_put_contents('rules.xml', $data); 
$xml = simplexml_load_file("rules.xml") or die("Error: Cannot create object"); 

print_r($xml); 

輸出繼電器

 
SimpleXMLElement Object 
(
    [child] => Array 
     (
      [0] => SimpleXMLElement Object 
       (
        [EC] => 1 
        [Descript] => Savings Accepted 
        [Logic] => RF > LF = PAID 
        [Rules] => RF is greater than PAID and LF is equal to PAID 
       ) 

      [1] => SimpleXMLElement Object 
       (
        [EC] => 2 
        [Descript] => Savings Declined 
        [Logic] => RF >= LF RF greater/equal PAID, LF equal PAID 
       ) 

     ) 

) 

來源:http://www.tutorialspoint.com/xml/xml_character_entities.htm https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

+0

HI理查德我想更改數據不手動,所以我怎麼做,因爲XML數據來自第三方服務 –

+0

你好Sandeep,XML無效。誰在給你發郵件?你可以給他們打電話,告訴他們這個XML是無效的嗎?這可能是如何處理它的最好方法。 – Richard