XML 파일을 만들려고하는데 XML 파일을 노드에 래핑해야하므로 추가하기가 쉽지 않습니다.PHP의 읽기, 쓰기 및 추가를 알고 있지만 삽입 할 수 있습니까? 또는 마지막 줄을 제거 하시겠습니까?
위의 사항에 도움이 될 것입니다.
내 XML은 2 개 개의 다른 노드 유형으로 구성 :
<entry id="1_0">
<title>This is the title</title>
<description>This is the description...</description>
<subName>Publishers Name</subName>
<date>Saturday, June 11th, 2007, 5:46:21 PM</date>
<BorF>bug</BorF>
</entry>
<vote id="1_0">5</vote>
그리고 PHP 파일
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script>
$(function(){
$("#addVote").click(function() {
$.ajax({
type: "POST",
url: "saveListData.php",
data: 'url=bugs_features_listdata.xml&listData=\n<vote id="1_2">3</vote>',
async: false,
cache: false,
success: function(data, textStatus) {
if (window.console) console.log(textStatus);
},
complete: function(XMLHttpRequest, textStatus){
if (window.console) console.log(textStatus);
}
});
});
$("#addEntry").click(function() {
$.ajax({
type: "POST",
url: "saveListData.php",
data: 'url=bugs_features_listdata.xml&listData=\n<entry id="1_1">\n\
\t<title>This is the title 1</title>\n\
\t<description>This is the description...</description>\n\
\t<subName>Publishers Name</subName>\n\
\t<date>Saturday, June 11th, 2007, 5:46:21 PM</date>\n\
\t<BorF>bug</BorF>\n\
</entry>',
async: false,
cache: false,
success: function(data, textStatus) {
if (window.console) console.log(textStatus);
},
complete: function(XMLHttpRequest, textStatus){
if (window.console) console.log(textStatus);
}
});
});
});
</script>
</head>
<body>
<a id="addVote" href="#">ADD VOTE</a><br /><br /><a id="addEntry" href="#">ADD ENTRY</a>
</body>
</html>
에 (현재 고정) 데이터를 전송하기 위해 jQuery를 사용하여 간단한 테스트 페이지를했습니다 .. 그것은 현재 XML 파일에 추가되지만 시작/끝 노드가 필요합니다.
, 당신은 $ 콘텐츠의 조각을 가지고 $ 콘텐츠 = ''처럼, 그것의 주위에 물건을 포장합니다. $ 콘텐츠. ' '; 파일에 다시 넣으시겠습니까? 당신은 내가 생각하기에 그 시작과 끝 노드를 제거 할 수 있기를 원합니 까? –
tomzx
SimpleXML과 같은 xml 라이브러리를 사용합니까? – txwikinger
내 게시물을 좀 더 자세히 업데이트했습니다 ... @tomzx 말하자면, 위에서 말한 노드들을 xml 파일에 모두 루트 노드에 멋지게 감쌌습니다 ( xml> . 루트 노드 내에 자식 노드 (위의 두 노드 중 하나)를 추가/추가하려고합니다. @txwikinger 현재 XML 라이브러리를 사용하고 있지 않습니다. 나는 그들이 일하는 방식에 익숙하지 않다 ... –