[英]How to actually delete(modify) nodes from XML file in flex?
祝大家好運,我已經有兩天了,但是即使在這個站點中,我仍然沒有得到正確的解決方案,因此我非常希望有人能夠為我提供一些答案。 提前致謝!
所以這是我的問題,我一直試圖從另一個包中的外部XML文件中刪除一個節點,這種方式會成功加載。 現在,我想刪除索引為[x]的節點,然后嘗試再次在xml文件中打印數據,我要刪除的節點不見了...但是...當我在目錄中打開文件時,該節點仍然存在,我嘗試刷新文件,仍然存在...請幫助我,這是我的代碼。
動作腳本代碼
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, loadXML);
var bookList: XML = new XML();
function loadXML(e:Event):void{
bookList = new XML(e.target.data);
delete bookList.book[3];
tlabel.text = bookList.book; //test lable coz trace wont work
}
xmlLoader.load(new URLRequest("xmldata/data.xml")); //Loading XML data
XML代碼
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer 123</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.</description>
</book>
</catalog>
您正在修改應用程序內部加載的xml數據,而不是實際的XML文件。 您需要將更改后的xml保存在該位置以查看更改。
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, loadXML);
var bookList: XML = new XML();
function loadXML(e:Event):void{
bookList = new XML(e.target.data);
delete bookList.book[3];
tlabel.text = bookList.book; //test lable coz trace wont work
// code to save your xml
var uploader:URLLoader = new URLLoader();
var data:URLVariables = new URLVariables();
data.xml = bookList.toXMLString();
var req:URLRequest = new URLRequest("http://locahost/saveXML.php");
req.method = URLRequestMethod.POST;
req.data = data;
uploader.load(req);
}
xmlLoader.load(new URLRequest("xmldata/data.xml")); //Loading XML data
PHP代碼
<?php
file_put_contents('path/to/file', $_POST['data']);
?>
希望能幫助到你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.