A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [CS3] How do I alter an attribute in an XML file?

  1. #1
    Member
    Join Date
    Nov 2006
    Posts
    79

    [CS3] How do I alter an attribute in an XML file?

    Hi all ,
    How do I alter an attribute in an XML file using AS 3.0?

    I have the folloiwng XML file:

    Code:
    <Books>
    	<Book ISBN="987854">
    		<title>Sherlock Holmes</title>
    		<author>Sir Aurthur
    </author>
    
    	</Book>
    
    	<Book ISBN="987854">
    		<title>Sherlock Holmes</title>
    		<author>Sir Aurthur</author>
    	</Book>
    
    	<Book ISBN="987854">
    		<title>Sherlock Holmes
    </title>
    
    		<author>Sir Aurthur</author>
    	</Book>
    
    	<Book ISBN="987854">
    		<title>Sherlock Holmes
    </title>
    
    		<author>Sir Aurthur</author>
    	</Book>
    </Books>
    And the following code in AS 3.0:

    Code:
    var xmlLoader:URLLoader = new URLLoader();
    var xmlData:XML = new XML();
     
    xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
     
    xmlLoader.load(new URLRequest("sampleXML.xml"));
    
    function LoadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    ParseBooks(xmlData);
    }
    
    function ParseBooks(bookInput:XML):void {
    	xxx.text=bookInput.Book.author[0];
    }
    where xxx is a textbox.

    Basically I want to be able to press a button and the AS 3.0 should alter the XML file e.g. change the authors name.

    Thanks !

    Q

  2. #2
    Member
    Join Date
    Jun 2006
    Location
    Croatia
    Posts
    90
    You can change the author's name by simply assigning new value:

    Code:
    bookInput.Book.author[0] = "New Author";
    But that only changes your bookInput XML object in Flash, if you want to save changes to your "sampleXML.xml" then you'll have to use some server side language like php to write those changes to your file. Hope this helps

    best regards

  3. #3
    Member
    Join Date
    Nov 2006
    Posts
    79
    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center