문제는 내가 XML에 쓸 때마다 루트 XML이 생성되고 있다는 것입니다. 주요 문제는 하위 설정 및 루트 정의입니다. Łza 의 도움을 받아 이제 루트 XML 노드는 무시됩니다. 그러면 하위를 설정하고 만든 다음 콘텐츠를 추가하십시오. 그리고 올바른 형식의 예가 있습니다.기존 XML에 노드 추가
$xml = simplexml_load_file('FILENAME.xml'); // Load XML File Need to add IF Statment to create if does not exist
$result = $xml->addchild('Result'); // Ignore Root NODE and Add Child Results
$result->addChild('Time', gmdate('D-M-Y -H:i:s')); // Rest of the below adds Child to Result and outputs results
$result->addChild('Channel', $Site);
$result->addChild('Type', '**');
$result->addChild('Process', $Status);
$result->addChild('SKU', $code->SKU);
$result->addChild('item', $item);
$result->addChild('Status', '$Feedback');
$result->addChild('ErrorID', '$Error');
$result->addChild('Message', '$Message');
$xml->asXml('FILENAME.xml'); //Write to file would be
// All of the above Code is using variables from another part of the script
출력 대신 SimpleXMLElement 라이브러리 하드 XML 생성을 사용하는
<Root>
<Result>
<Time>Fri-May-2013 -09:15:22</Time>
<Channel>20</Channel>
<Type>**</Type>
<Process>Update</Process>
<SKU>98746524765</SKU>
<Item/>
<Status>Problem</Status>
<ErrorID>999-Error</ErrorID>
<Message>Unknown file format support</Message>
</Result>
<Result>
<Time>Fri-May-2013 -09:15:22</Time>
<Channel>20</Channel>
<Type>**</Type>
<Process>Update</Process>
<SKU>5412254785</SKU>
<Item/>
<Status>Problem</Status>
<ErrorID>123-Error</ErrorID>
<Message>Invalid Item</Message>
</Result>
</Root>
감사
당신이 새로운 추가 하시겠습니까 :
는 이것을 XML을 생성합니다
단순히 사용하는 파일을로드하려면 ''노드 아래의 노드 ''? 또한 당신은 하나의 또 다른 노드''을 가지고 있기 때문에. 그들 사이에 차이가 있습니까? –
NullPointer
죄송합니다. 내 바보 같은 실수입니다.을 노드로 보내고 싶습니다. 나는 원래의 게시물을 편집 할 것입니다. –
user1145101
정확히 원하는 것을 간단히 설명 할 수 있습니까? 코드를 작성 했으므로 코드가 작동하지 않습니까? 또는 그것에 오류가 있습니까? – NullPointer