xml 파싱 error
본문
왜 아래와 같은 오류가 나는건가요?
$string = str_replace('<','<', str_replace('>', '>', $response));
$xml = simplexml_load_string("$string");
Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in
Warning: simplexml_load_string(): <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv=" in
Warning: simplexml_load_string(): ^ in
$string 값은 아래와 같습니다.
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://url" xmlns:n1="http://url" xmlns:n="http://url">
<soapenv:Body>
<n:ProductOrderListResponse>
<n:ProductOrderInfoList>
<n1:LastChangedDate>2011-12-31T15:00:00.00Z</n1:LastChangedDate>
<n1:LastChangedStatus>PAY_WAITING</n1:LastChangedStatus>
<n1:OrderID>ORDERNO100000001</n1:OrderID>
<n1:ProductOrderID>PONO100000000001</n1:ProductOrderID>
<n1:ProductOrderStatus>PAYMENT_WAITING</n1:ProductOrderStatus>
</nProductOrderInfoList>
</n:ProductOrderListResponse>
</soapenv:Body>
</soapenv:Envelope>
답변 2
제일 첫 문자가 '<' 로 시작해야 하는데.. 그렇지 않다는 이야기입니다.
가령,
$string = "<?xml version~";
이 아닌..
$string = "
<?xml version
~";
처럼 되어있다면 해당 메시지가 나올 수 있습니다.
그리고 따옴표 처리도 되어야 합니다. " -> \"
<?php
$myXMLData =
"<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv=\"http://url\" xmlns:n1=\"http://url\" xmlns:n=\"http://url\">
<soapenv:Body>
<n:ProductOrderListResponse>
<n:ProductOrderInfoList>
<n1:LastChangedDate>2011-12-31T15:00:00.00Z</n1:LastChangedDate>
<n1:LastChangedStatus>PAY_WAITING</n1:LastChangedStatus>
<n1:OrderID>ORDERNO100000001</n1:OrderID>
<n1:ProductOrderID>PONO100000000001</n1:ProductOrderID>
<n1:ProductOrderStatus>PAYMENT_WAITING</n1:ProductOrderStatus>
</nProductOrderInfoList>
</n:ProductOrderListResponse>
</soapenv:Body>
</soapenv:Envelope>";
$xml = simplexml_load_string($myXMLData) or die("Error: Cannot create object");
print_r($xml);
$string = str_replace('<','<', str_replace('>', '>', $response));
이 부분을 빼고 하면 어떻게 나오나요?