我正在尝试用PHP读取xml文件并显示它。 这是我的代码:
$xml=simplexml_load_file("fichier.xml") or die("Error: Cannot create object");
foreach($xml->children() as $ibanstructure) {
foreach($ibanstructure->children() as $child){
//echo $child->getName().";";
if($child==""){
echo ";";
}
else{
echo $child . ";";
}
}
echo "<br>";}
这是我的xml文件,我只会显示一些行,因为有超过70行。
<?xml version="1.0" encoding="UTF-8"?>
<dataexport product="ibanstructure" filetype="full" filedate="20160527">
<ibanstructure><tag>IS</tag><modification_flag>U</modification_flag><iban_country_code>AD</iban_country_code><iban_country_code_position>1</iban_country_code_position><iban_country_code_length>2</iban_country_code_length><iban_check_digits_position>3</iban_check_digits_position><iban_check_digits_length>2</iban_check_digits_length><bank_identifier_position>5</bank_identifier_position><bank_identifier_length>4</bank_identifier_length><branch_identifier_position>9</branch_identifier_position><branch_identifier_length>4</branch_identifier_length><iban_national_id_length>8</iban_national_id_length><account_number_position>13</account_number_position><account_number_length>12</account_number_length><iban_total_length>24</iban_total_length><sepa>N</sepa></ibanstructure>
<ibanstructure><tag>IS</tag><modification_flag>U</modification_flag><iban_country_code>AE</iban_country_code><iban_country_code_position>1</iban_country_code_position><iban_country_code_length>2</iban_country_code_length><iban_check_digits_position>3</iban_check_digits_position><iban_check_digits_length>2</iban_check_digits_length><bank_identifier_position>5</bank_identifier_position><bank_identifier_length>3</bank_identifier_length><branch_identifier_position/><branch_identifier_length>0</branch_identifier_length><iban_national_id_length>3</iban_national_id_length><account_number_position>8</account_number_position><account_number_length>16</account_number_length><iban_total_length>23</iban_total_length><sepa>N</sepa></ibanstructure>
<ibanstructure><tag>IS</tag><modification_flag>U</modification_flag><iban_country_code>KW</iban_country_code><iban_country_code_position>1</iban_country_code_position><iban_country_code_length>2</iban_country_code_length><iban_check_digits_position>3</iban_check_digits_position><iban_check_digits_length>2</iban_check_digits_length><bank_identifier_position>5</bank_identifier_position><bank_identifier_length>4</bank_identifier_length><branch_identifier_length>0</branch_identifier_length><iban_national_id_length>4</iban_national_id_length><account_number_position>9</account_number_position><account_number_length>22</account_number_length><iban_total_length>30</iban_total_length><sepa>N</sepa><optional_commence_date/><mandatory_commence_date>20151101</mandatory_commence_date></ibanstructure>
</dataexport>
有点难以阅读但是当我使用Oxygen XML Editor显示时,这就是我获得的这3行。我将展示一些重要的专栏(第1,第2,第9,第10,第11,第12,第17和第18)。总共有18列。
Tag; modification_flag; ...; bank_identifier_length; branch_identifier_position;branch_identifier_length; ban_national_id_length; ...; optional_commence_date; mandatory_commence_date
时; U; ...; 4; 9; 4; 8; ...;空值; NULL
时; U; ...; 3;空值; 0; 3; ...;空值; NULL
时; U; 4;空值; 0; 4; ...;空值; 20151101
这就是我的PHP代码
时; U; AD; 1; 2; 3; 2; 5; 4; 9; 4; 8; 13; 12; 24; N;
时; U; AE; 1; 2; 3; 2; 5; 3; 0; 3; 8; 16; 23; N;
时; U; KW; 1; 2; 3; 2; 5; 4; 0; 4; 9; 22; 30; N; 20151101;
如您所见,当没有值(NULL)时,我的代码不会显示它。 我们应该为第一行18个值而不是16个用3“;”在末尾。对于第二行3相同;; 0; 3而不是3; 0; 3。而对于最后一个。 有人能告诉我我的代码有什么问题吗?
由于
答案 0 :(得分:0)
当我测试时,我得到了以下输出。这似乎是正确的。让我知道这是输出应该是什么。
IS;U;AD;1;2;3;2;5;4;9;4;8;13;12;24;N;
IS;U;AE;1;2;3;2;5;3;;0;3;8;16;23;N;
IS;U;KW;1;2;3;2;5;4;0;4;9;22;30;N;;20151101;