2010-05-17 7 views
0

양식의 텍스트 영역 입력을 통해 제출 된 XML 데이터를 가져 와서 데이터를 추출하여 데이터베이스에 던질 프로젝트를 진행 중입니다. XML의 루트 필드에있는 속성에 대한 오류가 발생합니다 (매번 같은 스키마이지만 값이 다릅니다). 이러한 속성을 제거하면 제대로 작동하지만 스크립트에 데이터를 전송할 때마다 이러한 속성을 제거하지 않아도됩니다. 여기 XML 루트 속성에 SimpleXMLElement (PHP) 오류가 발생했습니다.

내가 (나에게 오류를 주시는 부분) 사용하고 내 데이터와 코드의 샘플입니다

: 나는 같은 데이터를 게시하는 경우

<raid generatedFrom="HeadCount" version="1.7.4"> 
--snip-- 
</raid> 

을, 나는 다음과 같은 오류가 발생할 수

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : AttValue: " or ' expected in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <raid generatedFrom=\"HeadCount\" version=\"1.7.4\"> in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]:^in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : attributes construct error in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <raid generatedFrom=\"HeadCount\" version=\"1.7.4\"> in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]:^in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Couldn't find end of Start Tag raid line 1 in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <raid generatedFrom=\"HeadCount\" version=\"1.7.4\"> in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]:^in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 1: parser error : Extra content at the end of the document in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: <raid generatedFrom=\"HeadCount\" version=\"1.7.4\"> in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Warning: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]:^in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php:13 Stack trace: #0 /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php(13): SimpleXMLElement->__construct('<raid generated...') #1 {main} thrown in /home/content/g/V/i/gViscardi/html/guilds/sanctum/headcount.php on line 13 

루트 노드에서 특성을 제거하면 오류없이 정상적으로 작동합니다.

다음 코드를 사용하여 표시합니다.

<html> 
<head> 
</head> 
<body> 
<?php 
if(isset($_POST['h_input'])) 
{ 
    //echo 
    //$xml_d = file_get_contents('php://input'); 
    $xml_d = $_POST['h_input']; 
    //print_r($xml_d); 
    $xml = new SimpleXMLElement($xml_d); 

    echo $xml->zone . "<br />"; 
    foreach ($xml->players->player as $player) { 
     echo $player->name . "<br />"; 
    } 
} else { 
?> 
<form action="headcount.php" method="post" name="headcount"> 
<textarea rows="10" cols="30" name="h_input"> 
</textarea> 
<input type="submit" /> 
</form> 
</body> 
</html> 

답변

6

magic_quote가있는 것으로 의심되어 백 슬래시가 XML에 추가됩니다.

백 슬래시를 제거하려고,

$xml_d = stripslashes($_POST['h_input']); 
+0

위대한 당신을 감사합니다! 그것은 그것을 고쳤다! – Greg

관련 문제