出力を保存する前に、データを取得し、DOM ドキュメントを作成し、必要なビットだけを転送して XML を再構築しようとしていますが、「XML 解析エラー: 要素が見つかりません: 行番号 1、列 1:" エラー。最初の空白タグに関連していると思います:
<?xml version="1.0" encoding="UTF-8"?>
<report title="My Programs" name="aAffiliateMyProgramsReport" time="2012-11-27 16:06">
<matrix rowcount="2">
<rows>
<row>
<>You must select one or more sale events before editing</>
</row>
</rows>
</matrix>
<matrix rowcount="2343">
<rows>
<row>
<siteName>thewebsite.com</siteName>
<affiliateId>123456</affiliateId>
<programName>TheProgram.com</programName>
<currentStatusExcel>Ok</currentStatusExcel>
<programId>203866</programId>
<applicationDate>2012-09-15</applicationDate>
<programTariffAmount>0.0</programTariffAmount>
<programTariffCurrency>GBP</programTariffCurrency>
<programTariffPercentage>0.0</programTariffPercentage>
<status>Accepted</status>
<event>Unique visitor</event>
<eventIdView>2</eventIdView>
<eventLastModified>2011-03-15</eventLastModified>
<segmentID>1</segmentID>
<segmentName>General</segmentName>
<lastModified>2012-09-15</lastModified>
</row>........
そして、ここに私が実行しようとしているPHPがあります:
//contents of MyPrograms report - tested $query in browser many times: it is correct
$query = $q1.$siteID.$q2.$rKey.$q3;
//create DOM document for newTree
$newTree = new DOMDocument();
$newTree->formatOutput =true;
$r = $newTree->createElement ("ProgramTariffs");
$newTree->appendChild($r);
//load contents of MyPrograms report into an xml element
//$oldTree = simplexml_load_file($query);
//that wasn't working so tried file_get_contents instead
$oldTree = file_get_contents($query);
//the above is now at least allowing this script to produce an xml file, but it just contains
"<?xml version="1.0"?> <ProgramTariffs/>"
//and still throws the no element found error.................................
//for each instance of a program id in $oldTree.....
foreach($oldTree->matrix->rows->row as $program)
{ //an attempt to skip over first $program if nothing is set
if (!empty($program->programId)) {
//create the top line container tag
$row = $newTree->createElement ("programTariff");
//create the container tag for programId
$progID = $newTree->createElement("programId");
//fill it with the information you want
$progID->appendChild ( $newTree->createTextNode ( $program->programId ) );
//attach this information to the row
$row->appendChild($progID);
//create the container tag for eventName
$eventName = $newTree->createElement("eventName");
//fill it with the information you want
$eventName->appendChild ( $newTree->createTextNode ( $program->event ) );
//attach this information to the row
$row->appendChild($eventName);
//create the container tag for eventAmount
$eventPercent = $newTree->createElement("eventPercent");
//fill it with the information you want
$eventPercent->appendChild ( $newTree->createTextNode ( $program->programTariffPercentage ) );
//attach this information to the row
$row->appendChild($eventPercent);
//attach all of the above to a row in NewTree
$r->appendChild ($row);
}
}
//save the output
$newTree->save("ProgramTariffs.xml");
元の XML へのアクセスで基本的な間違いを犯したのでしょうか、それとも "<>" のタグ名を含む行を回避するためのより良い方法を見つける必要がありますか?
私はあなたの怒り/救いを待っています