AS3.0 iterating through XML file

I am new to AS3.0 and the new E4X way of working with XML.
I'm trying to loop through a portion of an externally loaded XML
file and display the results. Here is a portion of my XML file:
<amenity id="1">
<title>The Gate House</title>
<feature>Majestic two-level Preserve Neighborhood
Amenity Center</feature>
<feature>Beautiful Gardens and Meandering
Pathways</feature>
<feature>Meeting Activity Room, Theatre Room, Gourmet
Kitchen, Hearth Room, Grand Fireplace</feature>
<feature>Decks and Patios</feature>
<feature>Available to residents for parties, reunions,
weddings, and meetings</feature>
</amenity>
The are other amenities as well. When a user clicks a button,
I want to enumerate all of the features from this particular
amenity. Here is my code to do this (the code associated with the
listener for the button):
function btnClick(eventObject) {
var mc:MovieClip=eventObject.target
var num:String = mc.name.replace("btn","")
var xmlAmenity:XMLList = myXML.amenity.(@id==num)
for each (var prop:XML in xmlAmenity) {
trace (prop.feature);
Basically the button that calls this is btn1, so the num
variable ends up being 1. myXML is a global variable into which the
external XML file has already been loaded. It then uses the num
variable to assign the amenity with an id if 1 to the xmlAmenity
variable as an XMLList. Everything works just grand except for the
fact that the trace produces the following:
<feature>Majestic two-level Preserve Neighborhood
Amenity Center</feature>
<feature>Beautiful Gardens and Meandering
Pathways</feature>
<feature>Meeting Activity Room, Theatre Room, Gourmet
Kitchen, Hearth Room, Grand Fireplace</feature>
<feature>Decks and Patios</feature>
<feature>Available to residents for parties, reunions,
weddings, and meetings</feature>
I don't want the tags, just what's inside them. Is there some
property I need to use (something like prop.feature.contents) or am
I going about this the wrong way entirely? I suppose I could
restructure my XML file to put the contents of the feature tag in
an attribute called description and then trace the attribute with
prop.feature.@description, but I'd kind of like to know how to
access the text inside the open and close of the tag. If I access
one directly (something like myXML.amenity.(@id==num).feature[0])
then it works just fine, I just can't seem to figure it out in a
loop. I suppose I could increment a variable and do something like
trace(myXML.amenity.(@id==num).feature[x]), but there must be a
better way.

Goodness sakes, that was a long post for a quick answer I
just figured out:
My loop should read like this:
for each (var prop:String in xmlAmenity.feature) {
trace (prop);
The key was enumerating through each xmlAmenity.feature, not
xmlAmenity. Of course, if there's a better way, I'm all
ears...

Similar Messages

  • Send Image through xml file

    Hey guys,
    I want to send an JPEG image through xml file. i dont want to just give the URL of the image but i want to actually send the image through xml. Im new in XML so can you please give me a working sample code.
    Thank you so much.

    Working code will not be difficult to write. Jpeg or other binary info can be encoded in xml using base64 encoding or some other encoding algorithm.
    After base64 encoding you will get some text which will be the base64 equivalent of the image data. This text can be placed in CDATA section of your image element and transferred.
    On the receiving end you will need to decode the text. After this what u have is the binary data for ur image.
    It will not be difficult to find libraries for base64 encodin/decoding on the net.
    Hope it helps

  • Update Database Through XML file using SAP B1 business objects

    Hello everyone,
    I am facing a problem ie I am not able to update the Database(SQL 2000) through an XML file.
    Though i am able to insert the data in the databse using xml file but unable to update that data.
    The tables i want to update are OITM,ITM1,OITW. While i was trying to update  the Databse i was getting an error ie " -1107 Object's key is not set".
    I dont want to use DTW for importing or anything.
    Kindly help me out why i am facing this problem asap...

    Hi Pranay,
    My case was that I wanted to replicate an item from one company to another (I guess that's your case also). What I finally did is copy field by field the objects I needed. Later I've find out the solution given here,
    Copy items between databases
    but I haven't try it out. I expect your comments about it :).
    Regards,
    Ian

  • Import and Export CSV Through XML File in Oracle

    Hi Gurus,
    I am sorry , I had deleted this post.
    Thanks
    Edited by: user10679113 on Feb 5, 2009 6:13 AM

    What does it mean to do something with comma separated values through XML. That is a new concept for me.
    Either something is CSV or XML but what is it you are trying to describe? Please provide an example.
    Then come the obvious questions like what version and edition of Oracle on what platform? What does any of this have to do with email? How large a file? etc.
    No one else has responded so I can only assume they are thinking what I am ... "what is this person trying to do?"

  • AS3 alternatives to *_exclude.xml files, loading class definitions dynamically

    I've been banging my head against a wall for this for almost a couple days now and hoping that someone can point me in the right direction.
    Working in a very large Flash application, previously in AS2/CS3 I would have a setup like the following:
    root.swf
    -- modules
    ---- code_a.swf
    ---- code_b.swf
    -- views
    ---- view_a.swf
    ---- view_b.swf
    Using _exclude.xml files, I could exclude the classes defined in code_a and code_b from the ouptut .swf of view_a and view_b. root.swf would be responsible for loading the code modules before view_a or view_b, ensuring that class definitions that view_a and view_b depended on existed.
    The Problem
    We've recently migrated to using Actionscript 3/CS5. *_exclude.xml files no longer exist. To get the same functionality as above, I've tried the following:
    My setup now looks something like:
    root.swf
    -- modules
    ---- class_a.as
    ---- class_b.as
    -- views
    ---- view_a.swf
    ---- view_b.swf
    Use mxmlc to compile root.swf, view_a.swf and view_b.swf, passing it -externs option to specify classes that will be loaded externally (the two classes in modules). This ensures that the class is excluded from the compiled swf.
    Use compc to compile class_a.as and class_b.as into classes.swf, using -directory=true to access library.swf for external loading.
    However, when I try running one of the two view files which depend on classes.swf, I get runtime errors telling me that a class definition is not present.
    Current Workaround
    I've devised a workaround which I'm currently not happy with as it's backwards to the modular approach that I was previously using:
    Rather than loading the code modules, I statically link all class definitions required by child movies intoroot.swf. When building root.swf, I use the -link-report option of mxmlc to provide a list of included classes. When building child swfs, I can the use -load-externs to ensure that class definitions that already exist will not be included in the compile output.
    Is there a way that anyone is aware of to replicate the AS2/_exclude.xml solution that I had using AS3/CS5?

    I'd double check if you are loading the child SWF with correct LoaderContext and/or calling ApplicationDomain.getDefinition() correctly - otherwise you cannot access classes defined in loaded SWF files.

  • Configuring SPA2102 through xml file

    Can anyone help me? I have an SPA2102 and i want to configure it through an xml file, but it doesnt seem to work, the xml im sending is the following:
    <flat-profile>
    <User_ID_1_>user</User_ID_1_>
    <Password_1_>password</Password_1_>
    </flat-profile>
    Since all i want to change is the account, but when i load it with the http://ipaddress/admin/resync?tftp... i get the following message,  SPA will resync the profile when it is not in use and reboot
    you can click HERE to return to the configuration page, but it never reboots,and if i do it manually, it stays the same, so i would appretiate if someone could help me, and point me in the right direction, telling what is that im doing wrong. Thanks in advance. 

    I will try to make it clearer:
    The server I have access to runs Tomcat through Apache. The only way I can access files is if I put them under httdocs.
    The question is quite simple: without having my clueless host remap everything, how can I access files in the Tomcat directory, where those files rightly belong?
    There should be a simple way to do it in a web.xml file, but have been unsuccessful thus far.

  • Traversing through xml file

    can anybody will tell me how can i access n print the particular node in xml file through DOM api in java(not DOMParser of XERCES)

    use utility classes like DOMwriter available with most of the parsers

  • Trouble looping through XML file

    I've got the following code which loops through an XML file. It works when there are multiple devices in the XML file and the COMPUTER node in the script includes [$i] but if only one device is in the network (thus only one in the XML file) then I have to
    remove the [$i]. What am I doing wrong to make it apply to both?
    $i = 0
    foreach ($COMPUTER in $settings.Settings.Setting.COMPUTERS.COMPUTER) {
    # IP for Computer
    $IPADDRESS = $settings.Settings.Setting.COMPUTERS.COMPUTER[$i].COMPUTERIP
    # Username for Computer
    $USERNAME = $settings.Settings.Setting.COMPUTERS.COMPUTER[$i].USERNAME
    # Credentials file
    $CREDFILE = $settings.Settings.Setting.COMPUTERS.COMPUTER[$i].CRED
    # Do things here using the variables declared above
    $i= $i+1
    } # Stop looping
    I should point out that I've changed the variable and XML names accordingly but the principle is the same.
    Thanks in advance

    Hi Bobbins,
    no, I just pasted that there so you can copy&paste it to the console and see the results. External XML sources are totally valid.
    To apply this to your initial script example, replace all instances of ...
    $settings.Settings.Setting.COMPUTERS.COMPUTER[$i]
    ... with ...
    $COMPUTER
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • How can I convert the metadata tags on my mp4s to xml files so that they can be read in Windows Media Center?

    I have a library with almost 3000 movies and TV shows that I have fully tagged. However, I have decided to start using Windows Media Center and it does its metadata tagging through XML files.  I wanted to know if anyone could tell me if there was a way to extract the metadata from those mp4s and convert them to a format that WMC could read?  Thanks!!!!

    iTunes can make XML playlists so it might be all you need, I made a simple one file playlist and exported it from iTunes. The result is shown below. In principle I could delete the playlist and the entry from the library, as long as I don't delete the file, then later reimport the XML playlist file. I haven't tested this particular scenario, but I assume that iTunes will read all the properties as listed unless it can read some kind of tag from the file itself in which case the current value of the tag would take precedence.
    What I don't know is what media center would make of this file, or what its files look like, however assuming they have a similar structure that can be decoded then it should be possible to read data from the iTunes library and write out a text file that will make sense to media centre.
    Video Test.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Major Version</key><integer>1</integer>
    <key>Minor Version</key><integer>1</integer>
    <key>Date</key><date>2013-09-26T23:30:26Z</date>
    <key>Application Version</key><string>11.1</string>
    <key>Features</key><integer>5</integer>
    <key>Show Content Ratings</key><true/>
    <key>Music Folder</key><string>file://localhost/E:/iTunes/iTunes%20Media/</string>
    <key>Library Persistent ID</key><string>CCF046191585EA85</string>
    <key>Tracks</key>
    <dict>
    <key>155170</key>
    <dict>
    <key>Track ID</key><integer>155170</integer>
    <key>Name</key><string>Abbott &#38; Costello: "Two Tens For A Five" &#38; "Who's On First"</string>
    <key>Artist</key><string>Abbott &#38; Costello</string>
    <key>Album Artist</key><string>Abbott &#38; Costello</string>
    <key>Album</key><string>Abbott &#38; Costello: "Two Tens For A Five" &#38; "Who's On First"</string>
    <key>Genre</key><string>Comedy Clip</string>
    <key>Kind</key><string>MPEG-4 video file</string>
    <key>Size</key><integer>110483524</integer>
    <key>Total Time</key><integer>532096</integer>
    <key>Year</key><integer>1950</integer>
    <key>Date Modified</key><date>2013-06-19T17:35:18Z</date>
    <key>Date Added</key><date>2012-12-01T17:30:57Z</date>
    <key>Bit Rate</key><integer>156</integer>
    <key>Comments</key><string>www.dvdvideosoft.com</string>
    <key>Artwork Count</key><integer>1</integer>
    <key>Persistent ID</key><string>5AF2C490D1E065CD</string>
    <key>Track Type</key><string>File</string>
    <key>Has Video</key><true/>
    <key>HD</key><false/>
    <key>Video Width</key><integer>1136</integer>
    <key>Video Height</key><integer>640</integer>
    <key>Location</key><string>file://localhost/E:/iTunes/iTunes%20Media/Home%20Vide os/Abbott%20&#38;%20Costello_%20_Two%20Tens%20for%20a%20Five_%20&#38;%20_Who's%2 0on%20First_.mp4</string>
    <key>File Folder Count</key><integer>3</integer>
    <key>Library Folder Count</key><integer>1</integer>
    </dict>
    </dict>
    <key>Playlists</key>
    <array>
    <dict>
    <key>Name</key><string>Video Test</string>
    <key>Playlist ID</key><integer>1930541</integer>
    <key>Playlist Persistent ID</key><string>30BF2769C94F7F29</string>
    <key>All Items</key><true/>
    <key>Playlist Items</key>
    <array>
    <dict>
    <key>Track ID</key><integer>155170</integer>
    </dict>
    </array>
    </dict>
    </array>
    </dict>
    </plist>
    Such files are easier to interpret if opened with Notepad++.
    tt2

  • Reading the datas in the Xml file  and store it in the array using java

    Hi every one
    Can any one send me the java coding for traversing through XML file and get the data and store it in the array (SAX parser is prefered)
    its a urgent requirement . please help me
    Regards
    Arun

    i send it to ur mail id ,
    could you please send me a mail to [email protected]

  • Walk through all files in a folder and do this for all subfolders and...

    ... and their subfolders, etc. I mean I want to recursively walk through all subfolders of a folder and when I'm "in" in each folder I would like to walk through all files alphabetically of that folder.
    While iterating through the files (of a certain type: .mp3, .mp4, .m4a) of that folder, I need to make a simple counter. e.g. when counter is 3 it means we are on the 3rd file alphabetically of the folder.
    Then I simply want to set the track # mp3 tag of that file to this counter value (e.g. 3)
    Anyone know how to do this? or at least to be able to show me the walking the folders and iterating the files bit? I'm brand new to applescript.
    Why do I want to do this? Well I have a lot of live music shows, each in its own folder, but in my apple devices and itunes when I play a show it will not show the songs in the correct order. The file names are alphabetical in the correct order though and I suspect if I assign track #s then itunes, ipods and iphones will be able to play the "album" back in the order listed by track #??

    What are you using to play your items? iTunes can use various properties to sort a playlist, independent of what the file name is (Finder too, for that matter). If you are just wanting to add a prefix number to a file name, you would also probably need to use leading zeros to keep it in order when sorted by name.
    The following is a general purpose handler to go through the items in a folder - I just put various text into the output list as an example.
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px; height: 340px;
    color: #000000;
    background-color: #FFEE80;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    on run -- example
    set TheFolders to (choose folder with multiple selections allowed)
    choose from list (ProcessStuff from TheFolders)
    end run
    to ProcessStuff from SomeItems
    process items contained in SomeItems, recursively descending the directory tree
    parameters - SomeItems [list]: the items to process
      returns [list]: a list of processed items
    set FilesList to {} -- this will be a list of processed items
    repeat with AnItem in SomeItems
    set AnItem to AnItem as text -- get the contents
    set FileInfo to (info for AnItem as alias) -- see Standard Additions
    if (folder of FileInfo) and not (package folder of FileInfo) then -- a folder (not a package)
    -- do something with the folder, if desired
    set the end of FilesList to "folder  " & AnItem
    try -- sort and process contents, skipping any errors
    tell application "Finder"
    set SubItems to (get items of folder AnItem)
    set SubItems to (sort SubItems by name) as alias list
    end tell
    set FilesList to FilesList & (ProcessStuff from SubItems)
    end try
    else -- a file
    -- do something with the file, if desired
    set the end of FilesList to tab & (name of FileInfo)
    end if
    end repeat
    return FilesList
    end ProcessStuff
    </pre>

  • JAXB duplicates database records in the output XML file

    I am trying to export a database through XML file using JAXB. But i get an XML file having my records with the @XMLElement name i gave it (SMS_Database) and also another one following it with <list/> as the RootElement name. I don't know where it's coming from. Here is the code:
    import java.io.*;
    import java.sql.*;
    import java.util.ArrayList;
    import javax.xml.bind.*;
    public class Parse2Xml {
      static final String XMLBASE = "./SMS_Database.xml";
      static ArrayList<Intermed> dataList = new ArrayList<Intermed>();
      static Connection con = null;
      static PreparedStatement ps = null;
      static ResultSet rs = null;
      public static void main(String[] args) throws JAXBException, IOException {
            con = getConnection();
            try{
              ps = con.prepareStatement("SELECT * FROM SMS_Log");
              rs = ps.executeQuery();
              while (rs.next()) {
                  dataList.add(getData(rs));
              rs.close();
              ps.close();
              con.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
            DataStore SMS_Database = new DataStore();
            SMS_Database.setList(dataList);
            JAXBContext context = JAXBContext.newInstance(DataStore.class);
         Marshaller m = context.createMarshaller();
         m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
         Writer w = null;
         try {
              w = new FileWriter(XMLBASE);
              m.marshal(SMS_Database, w);
         } finally {
              try {
                   w.close();
              } catch (Exception e) {
        static Connection getConnection(){
            String sqlURL = "jdbc:mysql://localhost:3306/SMSDB";
            String username = "SUNNYBEN";
            String password = "drowssap";
            try {
                try {
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                } catch (InstantiationException ex) {
                    ex.printStackTrace();
                } catch (IllegalAccessException ex) {
                    ex.printStackTrace();
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            try {
                con = DriverManager.getConnection(sqlURL, username, password);
            } catch (SQLException ex) {
               ex.printStackTrace();
            return con;
        static Intermed getData(ResultSet rs) throws SQLException {
                Intermed mediator = new Intermed();
                mediator.setSms_id(rs.getString("sms_id"));
                mediator.setSender_id(rs.getString("sender_id"));
                mediator.setMessage(rs.getString("message"));
                mediator.setPhone_no(rs.getString("phone_no"));
                mediator.setDate_sent(rs.getString("date_sent"));
                mediator.setSchedule_date(rs.getString("schedule_date"));
                mediator.setUsername(rs.getString("username"));
                mediator.setResponse(rs.getString("response"));
                return mediator;
    import java.util.ArrayList;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    @XmlRootElement(namespace = "SMS_Database")
    class DataStore {
        @XmlElement(name = "SMS_Log")
        ArrayList<Intermed> dataList = new ArrayList<Intermed>();
        public ArrayList<Intermed> getList() {
            return dataList;
        public void setList(ArrayList<Intermed> dataList) {
            this.dataList = dataList;
    import javax.xml.bind.annotation.*;
    @XmlRootElement(name = "SMS_Log")
    @XmlType(propOrder = {"sms_id", "sender_id", "message", "phone_no", "date_sent", "schedule_date", "username", "response"})
    public class Intermed {
        private String sms_id;
        private String sender_id;
        private String message;
        private String phone_no;
        private String date_sent;
        private String schedule_date;
        private String username;
        private String response;
        public String getSms_id() {
            return sms_id;
        public void setSms_id(String sms_id) {
            this.sms_id = sms_id;
        public String getSender_id() {
            return sender_id;
        public void setSender_id(String sender_id) {
            this.sender_id = sender_id;
        public String getMessage() {
            return message;
        public void setMessage(String message) {
            this.message = message;
        public String getPhone_no() {
            return phone_no;
        public void setPhone_no(String phone_no) {
            this.phone_no = phone_no;
        public String getDate_sent() {
            return date_sent;
        public void setDate_sent(String date_sent) {
            this.date_sent = date_sent;
        public String getSchedule_date() {
            return schedule_date;
        public void setSchedule_date(String schedule_date) {
            this.schedule_date = schedule_date;
        public String getUsername() {
            return username;
        public void setUsername(String username) {
            this.username = username;
        public String getResponse() {
            return response;
        public void setResponse(String response) {
            this.response = response;
    }

    Dear All
    my requirement is to generate an xml file which looks similar to
    <?xml version="1.0" encoding="UTF-8"?>
    <?TestLine?>
    <test_mt>
    <field1>123</field1>
    <field2>234</field2>
    </test_mt>
    how to add <?TestLine?>  tag?
    Hi shabrasish and rajashekar
    i am new to java and xslt mapping can you guide me  or give me links which are similar to my requirement how to proceed with this kind of mapping
    thanks
    uday

  • How to send a request and get a response through xml

    How to send a request and get a response through xml files?

    This is the code that works for me. Hope you find it useful.
         public static String sendHttpGetRequest(String endpoint, String requestParameters){
              String result = null;
              // Send a GET request to the servlet
              try{
                   // Send data
                   String urlStr = endpoint;
                   if (requestParameters != null && requestParameters.length () > 0){
                        urlStr += "?" + requestParameters;
                   URL url = new URL(urlStr);
                   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                   conn.setRequestProperty("Accept", "application/xml");
                   // Get the response
                   BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                   StringBuffer sb = new StringBuffer();
                   String line;
                   while ((line = rd.readLine()) != null){
                        sb.append(line);
                   rd.close();
                   result = sb.toString();
              } catch (Exception e){
                   e.printStackTrace();
              return result;
         }

  • Can I send an XML file to the server instead of just URL?

    I have installed the XML demos on my machine. I am using Oracle 8i. All the demos talks about getting URL and Parameter from the HTML Page, instead of this I want to send my XML file from Java Applet to server. Then do all the searching as is going on right now in the demos. After this I want to send another XML file back from server to client applet.
    Client ----->XMLFILE------>SERVER
    Client<-----XMLFILE<------SERVER
    Do we have any DEMO which shows that how to send request through XML file instead of
    "http://MachineName:Port/XSQL/DEMO/emp.xsql?find=A".
    I know that we are not using Java Applets in the demos but I will interact this file with applet, it's not a problem.
    I would appreciate if anyone who is really knowlegeable about these demos can answer my question.
    Thanks,
    Raza
    null

    http://forum.java.sun.com/thread.jspa?threadID=5158333
    http://forum.java.sun.com/thread.jspa?threadID=5158705
    Crossposting is lame.

  • Updating Gallery Pictures From xml file

    Hello there im editing a website and it had a gallery of
    pictures with several categories this is the link of the gallery
    http://www.jeweltechinter.com/jeweltech/gallery/gallery.html
    but there is no way i can update the picture need some help
    to know what should i do to update pictures i heard through xml
    file but i dont know how if someone can help me that would be
    great.
    thx in advance

    Hello ,
    Try this out ..
    http://www.kirupa.com/developer/mx2004/xml_flash_photogallery.htm
    Cheers,
    Srirama S

Maybe you are looking for

  • After click submit i get this message evrytime

    Hi all , in compresseor when i assigned a setting and a destination i click submit and everytime i get this message " One or more targets are incomplete" it also says "each target assigned to a job must have a setting and destination. I followed the

  • Class attribute in technical workflow log not updated

    Hi Gurus, I built a workflow analogous to the famous demo workflow "demoformabs" but with the demo class: CL_SWF_FORMABSENC instead of the BOR: FORMABSENC. In the BOR Formabsenc there is also an attribute for the "Approver" (USR01) in addition to "Cr

  • Same Company STO

    Dear SAP Guru's, A little confusion over the STO from one plant to other plant (OF THE SAME COMPANY CODE) We create PO. Then Replinishment Delivery NLCC Then GRN of the STO. After which is there any necessity for billing of the Delivery(NLCC) for STO

  • Filling "Ignore White" holes after Live Trace/Expand

    I'm relatively new to Illustrator CS4's Live Trace feature but have been using it a lot lately. When I place a Photoshop image (shot on white background) using Live Trace with the "Ignore White" box selected, it does a nice job of knocking out the ba

  • 11 CS & CC update downloads instant fail (49)? - all others update ok.

    Using iMac OS X Yosemite 10.10.1 with Creative Cloud, eleven CS and CC updates constantly fail with "Download error. Press Retry to try again or contact customer support.(49)"  Updates never appear to start, they just instant fail with the above erro