Load XML file from different location?

Hi All,
I've been going through an exercise by Karl Matthews to load XML data into an AIR App:
http://www.adobe.com/devnet/air/flex/articles/xml_viewer_on_air.html
but I would like to change where the XML file used in the project is retrieved from.
Currently the XML file is loaded from here:
<!-- Set up the HTTP service from where we get the source XML data -->
<mx:HTTPService id="srcData" url="
assets/UserGuide.xml" result="loadModelData(event)"
/>
but I would like to load the XML file from one of these locations instead:
File.userDirectory:
File.documentsDirectory:
Can someone please show me how I should change the above code to accomplish this, as my efforts to date have not been successful :-(
I am using Flex Builder 3 and Air 1.5.
Thanks heaps!
Tim

Hi Bhasker,
Thank you for replying.
I am not very good at all this coding, but I am assuming I should now be doing entering the following:
=======================
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication 
xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"width="
800" height="660"xmlns:comp="
*" xmlns:fmtComp="fmtComps.*"creationComplete="srcData.send()"
paddingLeft="
0" paddingRight="0" paddingTop="0" paddingBottom="0">
<mx:Script>
<![CDATA[
import mx.utils.ObjectProxy; 
import mx.rpc.events.ResultEvent; 
Bindable] 
private var userManualObj:ObjectProxy; 
private function loadModelData(event:ResultEvent):void
userManualObj=event.result.UserManual;
private function readXMLContent(xmlFile:File,objContentView:Object):Array{
var reportDir:File = File.userDirectory.resolvePath("assets"); 
var xmlFile:File; 
var fileStream:FileStream = new FileStream(); xmlFile = reportDir.resolvePath(
"UserGuide.xml"); 
if(xmlFile.exists && xmlFile.size > 0)// Checking if the impressions.xml file already exists and the file is not empty
var stream:FileStream = new FileStream(); 
var xml:XML = new XML();stream.open(xmlFile, FileMode.READ);
xml = XML(stream.readUTFBytes(stream.bytesAvailable));
stream.close();
]]>
</mx:Script>
<!-- Set up the HTTP service from where we get the source XML data<mx:HTTPService id="srcData"
url="assets/UserGuide.xml"
result="loadModelData(event)"/> -->
<mx:VBox width="100%" horizontalAlign="left" height="100%" paddingBottom="
0" paddingLeft="0" paddingRight="0" paddingTop="0">
<mx:TabNavigator width="100%" height="100%"paddingBottom="
0" paddingLeft="0" paddingRight="0" paddingTop="0">
<mx:Repeater id="modelsRep" dataProvider="{userManualObj.Product.Model}">
<mx:VBox label="{modelsRep.currentItem.Name}" width="100%" height="100%">
<comp:ModelDesc model="{modelsRep.currentItem}"/>  
</mx:VBox>
</mx:Repeater>
<mx:VBox label="Troubleshooting" width="100%" height="100%"paddingBottom="
0" paddingLeft="0" paddingRight="0" paddingTop="0">
<comp:Troubleshooting issues="{userManualObj.Product.Troubleshooting.Issue}" />
</mx:VBox>
</mx:TabNavigator>
</mx:VBox></mx:WindowedApplication>
=======================
and create and "assets" folder in my user directory placing the XML file in there?
However when I do all that, I get this error when I try to compile:
  Encountered errors or warnings while building project main.mxml.
    main.mxml: Function does not return a value.
Any thoughts?
Many thanks,
Tim

Similar Messages

  • Load XML file from addon domain without cross-domain Policy file

    Hello.
    Assuming that there are two addon domains on the same server: /public_html/domain1.com       and      /public_html/domain2.com
    I try to load XML file from domain2.com into domain1.com without using cross-domain policy file (since it doesn’t work on xml files in my case).
    So the idea is to use php file in order to load XML and read it back to flash.
    I’ve found an interesting scripts that seems to do the job but unfortunately I can't get it to work. In my opinion there is somewhere problem with AS3 part. Please take a look.
    Here are the AS3/PHP scripts:
    AS3 (.swf in www.domain1.com):
    // location of the xml that you would like to load, full http address
    var xmlLoc:String = "http://www.domain2.com/MyFile.xml";
    // location of the php xml grabber file, in relation to the .swf
    var phpLoc:String = "loadXML.php";
    var xml:XML;
    var loader:URLLoader = new URLLoader();
    var request:URLRequest = new URLRequest(phpLoc+"?location="+escape(xmlLoc) );
    loader.addEventListener(Event.COMPLETE, onXMLLoaded);
    loader.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);
    loader.load(request);
    function onIOErrorHandler(e:IOErrorEvent):void {
        trace("There was an error with the xml file "+e);
    function onXMLLoaded(e:Event):void {
        trace("the rss feed has been loaded");
        xml = new XML(loader.data);
        // set to string, since it is passed back from php as an object
        xml = XML(xml.toString());
        xml_txt.text = xml;
    PHP (loadXML.php in www.domain1.com):
    <?php
    header("Content-type: text/xml");
    $location = "";
    if(isset($_GET["location"])) {
        $location = $_GET["location"];
        $location = urldecode($location);
    $xml_string = getData($location);
    // pass the url encoded vars back to Flash
    echo $xml_string;
    //cURLs a URL and returns it
    function getData($query) {
        // create curl resource
        $ch = curl_init();
        // cURL url
        curl_setopt($ch, CURLOPT_URL, $query);
        //Set some necessary params for using CURL
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       //Execute the curl function, and decode the returned JSON data
        $result = curl_exec($ch);
        return $result;
        // close curl resource to free up system resources
        curl_close($ch);
    ?>

    I think you might be right about permissions/settings on the server for php. Unfortunately I'm not allowed to adjust them.
    So I wrote my own script - this time I used file path instead of http address of the XML file.  It works fine in my case.
    Here it is:
    XML file on domain2.com:
    <?xml version="1.0" encoding="UTF-8"?>
    <gallery>
        <image imagePath="galleries/gallery_1/images/1.jpg" thumbPath="galleries/gallery_1/thumbs/1.jpg" file_name= "1"> </image>
        <image imagePath="galleries/gallery_1/images/2.jpg" thumbPath="galleries/gallery_1/thumbs/2.jpg" file_name= "2"> </image>
        <image imagePath="galleries/gallery_1/images/3.jpg" thumbPath="galleries/gallery_1/thumbs/3.jpg" file_name= "3"> </image>
    </gallery>
    swf  on domain1.com:
    var imagesXML:XML;
    var variables:URLVariables = new URLVariables();
    var varURL:URLRequest = new URLRequest("MyPHPfile.php");
    varURL.method = URLRequestMethod.POST;
    varURL.data = variables;
    var MyLoader:URLLoader = new URLLoader;
    MyLoader.dataFormat =URLLoaderDataFormat.VARIABLES;
    MyLoader.addEventListener(Event.COMPLETE, XMLDone);
    MyLoader.load(varURL);
    function XMLDone(event:Event):void {
        var imported_XML:Object = event.target.data.imported_XML;
        imagesXML = new XML(imported_XML);
       MyTextfield_1.text = imagesXML;
       MyTextfield_2.text = imagesXML.image[0].attribute("thumbPath");  // sample reference to attribute "thumbPath" of the first element
    php file on domain1.com:
    <?php
    $xml_file = simplexml_load_file('../../domain2.com/galleries/gallery_1/MyXMLfile.xml');  // directory to XML file on the same server
    $imported_XML = $xml_file->asXML();
    print "imported_XML=" . $imported_XML;
    ?>
    Regards
    PS: for those who read the above discussion: the first and the second script work but you must test which one is better in your situation. The first script will also work between two domains on different servers. No cross domain policy file needed.

  • Can I load xml file from SWC without using @embed

    I'm developing a mobile application in which I need to load xml files from File.applicationDirectory. This works great if the xml files are part of the main application swf. But I would like to move these xml files into a SWC so they could be shared across multiple applications.
    Using FlashBuilder 4.5, when a SWC is built, I can specify files to embed in the library that are not assets (Assets Tab of Flex Library Build Path). For various design reasons, I do NOT want to embed the xml files via @embed.
    When the swc is built and I open it up using a zip utility, I see the xml files in there just fine. So they are being bundled with the SWC. But how can I load these files in my main application that does not involve using @embed? When the main application is built, the swc setting for link type is "merged into code".
    I wouldn't expect the application to automatically pull out the xml files from the swc and place them in the File.applicationDirectory on the mobile device. I've tried loading from there just in case but file.exists is false (as expected).
    I've searched the web (and continue to do so) and all the answers seem to be to use @embed. Is there another way?
    Randy

    It's actually a lot easier than you think.
    Just reference the file like any'ol URL using a path relative to the SWC's src directory.
    So if you include the file "assets/xml/some.xml", just use that same string like you would any remote resource.
    For example:
    var loader:URLLoader = new URLLoader( new URLRequest("assets/xml/some.xml"));
    I believe it would also work like this "/assets/xml/some.xml", but I prefer relative paths so the link doesnt break if moved out of the SWC...

  • Reading XML file from specific location&Storing xmldata into related tables

    I am new to xml.
    My requirement is,
    1) Get the xml file from specified location (C:\xmlfiles\ xmldata.xml)
    2)Convert xml data in clob data.
    3)store the data into related table.
    and vice-versa.
    What i did,
    a) I got the data from related tables and converted into xmlformat using SQLX
    b)converted this resultset into clob data and stored as xml file in specific location.
    It uses more then ten tables.
    All this help i got from AskTom site , thanks for that.
    Now i have to do vise-versa, i.e. i have to perform 1), 2), 3) steps........
    Please tell me proper steps to acheive it.
    Thanks in advance for giving your precious time to solve my issue.

    Have you read the"XMLDB FAQ" in this Forum?
    You could use stuff like:
    create or replace directory xmldir as C:\xmlfiles'
    declare
    xmldata xmltype;
    begin
    xmldata := xmltype(bfilename('XMLDIR','xmldata.xml'),nls_charset_id('AL32UTF8'));
      -- etc, etc your code --
      -- --> convert to clob by using for instance getclobval() function
      -- --> then insert the data in your relational table with CLOB column
      -- etc, etc your code --
    end;
    /

  • Read XML file from different server on JSP

    Dear All,
    I am a newbie to JSP with XML, now i want to read the "test.xml" from JSP.
    I read successfully this "test.xml" file from my system and I got output, but I need to read the xml file from
    different server like "http://www.domain.com/test.xml". I couldn't read such a type of file from different server.
    Is it possible to read a xml file from different server?
    If anybody have idea please let me know.
    Thanks in Advance,
    Prasath.
    <%@ page import="java.sql.*,java.io.*,java.util.*,javax.xml.parsers.*,org.w3c.dom.*,org.xml.sax.*" %>
    <%
    try {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        Document doc = docBuilder.parse (new File("http://www.domain.com/test.xml"));
        // normalize text representation
        doc.getDocumentElement ().normalize ();
        out.println ("Root element of the doc is " +
             doc.getDocumentElement().getNodeName()+"<br>");
        NodeList listOfPersons = doc.getElementsByTagName("person");
        int totalPersons = listOfPersons.getLength();
        out.println("Total no of people : " + totalPersons+"<br>");
        for(int s=0; s<listOfPersons.getLength() ; s++){
            Node firstPersonNode = listOfPersons.item(s);
            if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
                Element firstPersonElement = (Element)firstPersonNode;
                NodeList firstNameList = firstPersonElement.getElementsByTagName("first");
                Element firstNameElement = (Element)firstNameList.item(0);
                NodeList textFNList = firstNameElement.getChildNodes();
                out.println("First Name : " +
                       ((Node)textFNList.item(0)).getNodeValue().trim()+"<br>");
                NodeList lastNameList = firstPersonElement.getElementsByTagName("last");
                Element lastNameElement = (Element)lastNameList.item(0);
                NodeList textLNList = lastNameElement.getChildNodes();
                out.println("Last Name : " +
                       ((Node)textLNList.item(0)).getNodeValue().trim()+"<br>");
                NodeList ageList = firstPersonElement.getElementsByTagName("age");
                Element ageElement = (Element)ageList.item(0);
                NodeList textAgeList = ageElement.getChildNodes();
                out.println("Age : " +
                       ((Node)textAgeList.item(0)).getNodeValue().trim()+"<br>");
            }//end of if clause
        }//end of for loop with s var
    }catch (SAXParseException err) {
    out.println ("** Parsing error" + ", line "
         + err.getLineNumber () + ", uri " + err.getSystemId ());
    out.println(" " + err.getMessage ());
    }catch (SAXException e) {
    Exception x = e.getException ();
    ((x == null) ? e : x).printStackTrace ();
    }catch (Throwable t) {
    t.printStackTrace ();
    %>

    You might try:
    Document doc = docBuilder.parse ("http://www.domain.com/test.xml");Alternatively use the java.net package to obtain an Input Stream to the xml document
    InputStream in = methodThatYouWriteYourselfCalledgetInputStreamForURI("http://www.domain.com/test.xml");
    Document doc = docBuilder.parse (in);cheers,
    evnafets

  • How to load jar files from remote location

    Hi all,
    I am trying to load jar files from remote server, from a servlet which is running on OC4j.
    For doing this,First I am getting ClassLoader by using ClassLoader.getSystemClassLoader() and then type casting it to URLClassLoader.
    But by doing it I am getting ClassCastException,because oc4j returns oracle.classloader.PolicyClassLoader instead of java.net.ClassLoader.
    Appreciate if anyone can tell me how to load remote jar files using oracle.classloader.PolicyClassLoader .
    Thanks
    Harish

    Hi,
    I suppose you know about this, but just in case.
    I have used jnpl to load jar files from remote location.
    Rowan

  • How to access Excel files from different locations?

    Hello,
    I have successfully tested the Excel sample on WLS 7, and trying to run it on
    the WLS 8.1.
    Anyways, the common question for both is, how to access an excel files from different
    locations (e.g. c:\path\1.xls, \\domain1\finance\fin.xls, \\domain1\marketing\customer.xls,
    \\domain2\accounts\vouchers.xls)?
    From example i can see that it picks from a specific path under repository.
    Thanks
    Ashok Gupta

    The custom function sets the MS-Excel default directory to System.getProperty("user.dir")+"/excel"
    (the domain directory), then opens the filename passed as a parameter. I assume
    that if you pass in the fully specified path for the excel file ( like d:\MyDir\data\test.xls),
    that it would open that file.
    - Mike
    "Ashok Gupta" <[email protected]> wrote:
    >
    Hello,
    I have successfully tested the Excel sample on WLS 7, and trying to run
    it on
    the WLS 8.1.
    Anyways, the common question for both is, how to access an excel files
    from different
    locations (e.g. c:\path\1.xls, \\domain1\finance\fin.xls, \\domain1\marketing\customer.xls,
    \\domain2\accounts\vouchers.xls)?
    From example i can see that it picks from a specific path under repository.
    Thanks
    Ashok Gupta

  • Loading XML files from URL

    Hi.
    My PL/SQL procedure loading xml files from oracle logical directory ("c:\temp") and inserting values into columns of the table. I use XSU with procedure:
    create or replace procedure insProc(xmlDoc IN CLOB, tableName IN VARCHAR2) is
    insCtx DBMS_XMLSave.ctxType;
    rows number;
    begin
    insCtx := DBMS_XMLSave.newContext(tableName); -- get the context handle
    rows := DBMS_XMLSave.insertXML(insCtx,xmlDoc); -- this inserts the document
    DBMS_XMLSave.closeContext(insCtx); -- this closes the handle
    end;
    For translate xml document to CLOB, I use :
    CREATE OR REPLACE function getdocument(
    p_directory in varchar2,
    p_filename in varchar2)
    return clob
    is
    l_bfile bfile;
    l_clob clob;
    begin
    l_bfile := bfilename(p_directory, p_filename);
    dbms_lob.open(l_bfile);
    dbms_lob.createtemporary(l_clob, true, dbms_lob.session);
    dbms_lob.loadfromfile(l_clob, l_bfile, dbms_lob.getlength(l_bfile));
    dbms_lob.close(l_bfile);
    return l_clob;
    end getdocument;
    I didn't have problem with this procedures. But now i want load my xml files from another computer (i want use URL, not oracle logical directory).
    How can i do it, using standart PL/SQL methods?

    Since you are parsing the XML what prevents you from delaying your requests for the image URL's? You can just as well add the image URL's to some kind of collection and load them after you have processed all the text content.

  • Multiple jar files from different locations

    Hello,
    I am having an applet that access code from two different jar files. Of them one is a common jar file for many applets. So I couldn't place it in the local dir as that of the applet's html. I am not using any web server.
         Just to give you a feel of it :
         <PARAM NAME = archive VALUE = "DVApplet.jar,DVVP.jar" > are the jar files my applet is dependant on. But DVVP.jar has to be accessed from a dir different from local dir.
         Will be glad if someone can throw some light on accessing different jar files from different dirs.
         Thanks for your time.
    Regards,
    Anantha

    [url=
    http://forum.java.sun.com/thread.jsp?forum=421&thread=425724&tstart=0&trange=100
    ]This question is a bit similar
    You can use a class loader to do such things.

  • Loading XML file from classpath...

    Hello all.
    Can anyone help me with loading an XML file from the classpath?
    The XML I need to load looks like this:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <QueueDispatcher>
      <QueueConfigEntry>
        <DataSource>
          <TableName><![CDATA[WPOrder]]></TableName>
        </DataSource>
        <DataSink>
          <JMSQueueName><![CDATA[OTL_WPORDER]]></JMSQueueName>
        </DataSink>
      </QueueConfigEntry>
    </QueueDispatcher>I'm trying to load the file with the following code:
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    InputStream  input = this.getClass().getResourceAsStream("/QueueDispatcherConfig.xml");
    StreamSource streamSource = new StreamSource(input);
    Transformer  transformer  = transformerFactory.newTransformer(streamSource);
    ....All I get at the moment is an exception:
    javax.xml.transform.TransformerException: stylesheet requires attribute: version
    Any ideas what I'm doing wrong?
    Thanks in advance

    What are you doing wrong? You're using a Transformer, which expects to be given an XSLT document. If you want to make a DOM from that then you should use a DocumentBuilder, or you could use a SAXParser if you just want to extract the data from the XML file as you read it.

  • How to pick different files from different locations

    suppose ur having multiple files(csv) from different locations,then how do u move those files to the SAP system.Please expalin me the scenario

    Venu,
    If the files are present in different folders, then you need different sender communication channels to bring this data to XI. Regarding connection with SAP, you can go for a proxy (If the webAs version is > 6.2) or else go for an IDOCor RFC adapter.
    Regards,
    Jai Shankar

  • Loading "font.properties" from different location

    Is it possible to tell the JVM to load "font.properties" files from a different location instead of "$JAVA_HOME/jre/lib"?
    Thanks in advance.
    Regards.

    Is it possible to tell the JVM to load
    "font.properties" files from a different location
    instead of "$JAVA_HOME/jre/lib"?
    Thanks in advance.
    Regards.I am also looking for a solution for this, since it's not a good idea to modify the JRE itself.
    Could anybody help? Thanks.

  • Loading XML file from desktop

    Hi Expects!
    I want to try out loading a XML file in BI 2004s. is it possible to load an existing file from the desktop to BI? or does it have to be 'pushed' by an external system only?
    We have created webservice datasource, but we cannot assign a source of data to this, as no such option is available.
    Thanks in advance
    Sushmita

    You may wish to have a look below-
    <b>Data Transfer Using Web Services</b>
    http://help.sap.com/saphelp_nw04s/helpdata/en/71/421640033ae569e10000000a155106/frameset.htm
    <b>Creating a Web Service for Loading Data</b>
    http://help.sap.com/saphelp_nw04s/helpdata/en/ab/0709407448c442e10000000a1550b0/content.htm
    Hope it Helps
    Chetan
    @CP..

  • Loading XML file from EAR root ?

    I would like to be able to load/read an XLM file stored in the EAR root (just aside JARs and WARs). That way it will be easy to find and modify the file.
    But I can't read it :-/
    Is it possible to do so, or am I just doing crap ?

    What are you doing wrong? You're using a Transformer, which expects to be given an XSLT document. If you want to make a DOM from that then you should use a DocumentBuilder, or you could use a SAXParser if you just want to extract the data from the XML file as you read it.

  • Load XML File From Repository

    Assume you declare a process variable of type XML. Is it possible using the Set Value service to fill this variable with an XML file that is in the repository?
    I was thinking something like this might work, but it doesn't seem to
    Location Expression
    /process_data/xml_data /Stuff/data/data.xml

    You would have to use a Read Content from Repository service to get it out then you can use the SetValue to manipulate as you see fit. The XPath expression cannot access the repository directly.

Maybe you are looking for

  • Automatic clearing of open items

    hi, we have customers with 'dummy-invoices' in our system. There is a document in FI with a value of 0,01 Euro on the customer. this document is an open item and never will be cleared. is there any possibility for automatic clearing of such open item

  • Inserting a logo into the header and footer

    Hey Team  I have a workbook with 5 worksheets. On sheet1 I have a button programed to open a new Word document; pull information from fields on 3 other sheets and creates a letter from that data. I have two company logos pasted into sheet5, Pic1 and

  • RMI Failover not working in 9.2?

    Setup: RMI's RTD.xml <cluster clusterable="true" load-algorithm="round-robin" > </cluster> <method name="*" idempotent="true" timeout="3000" > </method> Cluster Srv1=RMI.instance1 Srv2=RMI.instance2 Srv3 Servlet: gets Srv1 context and looks up RMI ob

  • Error message for iTunes radio

    Two days ago I got this message when I tried to listen to the radio through iTunes. "An error occurred while contacting the radio tuning service. Check your internet connection, or try again later." My internet connection is fine. It still won't conn

  • Method to identify the value difference

    Dear Experts, We run a blocked invoices report (t-code ZMR0) from which the invoices are manually released. This report, among other details, is calculating and displaying the value difference for which the respective invoice got price blocked. As I