Sax Parser for loading XML file

We have a requirment by which we need to load huge XMl file in our DB everyday.
THe XML file format is like --
<?xml version="1.0" encoding="UTF-8"?>
<root>
<emp>
<ename>aaa</ename>
<sal>3000</sal>
</emp>
<emp>
<ename>bbb</ename>
<sal>5000</sal>
</emp>
<dept>
<name>productiong</name>
<location>USA</location>
<dept>
I have written XMl SAX parser to load this file into DB -
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;
import java.io.*;
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.xml.sql.*;
import oracle.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;
import java.util.*;
public class test extends DefaultHandler
String thisElement="";
String table_name="";
String table_name_2="";
String sql="";
String value_clause="";
StringBuffer value_clauseBuffer;
String Insert_sql="";
int flag;
String columnNames="";
String questionmarks="";
static String conStr = "jdbc:oracle:thin:@abcd1234:1521:dss501";
static Connection conn;
String arrayValues[] = new String[30];
int j = 0;
int emptyElementFlag = 0;
public SurveyReader() throws SQLException, FileNotFoundException, IOException{
DBConnect("username", "password");
public static void DBConnect(String username, String password)
throws SQLException, FileNotFoundException, IOException {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
conn = DriverManager.getConnection(conStr, username, password);
conn.setAutoCommit(true);
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
thisElement = qName;
if (thisElement!=table_name){
columnNames = columnNames + ", " + qName;
questionmarks = questionmarks +", " + "?";
emptyElementFlag =0;
public void characters(char[] ch, int start, int length)
throws SAXException {
if (thisElement !="root"){     
if ((length == 0) && (thisElement !="") ){
table_name = thisElement;
sql = " Insert into "+ table_name +"(";
value_clause="";
value_clauseBuffer =null;
columnNames = "";
questionmarks ="";
j =0;
if ((length != 0) && (thisElement!="") && (thisElement!=table_name)){
emptyElementFlag = 1;
String s = new String(ch, start, length);
String newString = s.replaceAll("'", "''");
// String newString = s;
if (value_clauseBuffer== null){
value_clauseBuffer = new StringBuffer(newString);
else{
value_clauseBuffer.append(newString);
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
if (thisElement !="root"){
if ((!(value_clauseBuffer == null))||((emptyElementFlag ==0) && (qName !=table_name))) {
try{
//value_clauseBuffer.append("', '");
if (value_clauseBuffer == null){
arrayValues[j]="";
else{
arrayValues[j]=""+value_clauseBuffer;
j = j+1;
value_clauseBuffer = null;
emptyElementFlag =0;
}catch(Exception e){
System.err.println(e);
System.exit(2);
if (qName == table_name){
if (!(value_clauseBuffer == null)){
value_clause = "'"+value_clauseBuffer;
columnNames =columnNames.substring(1, columnNames.length());
int paramNumber = j;
questionmarks =questionmarks.substring(1, questionmarks.length());
sql = sql + columnNames + " ) values (" + questionmarks +"); ";
Insert_sql=Insert_sql + sql;
sql = "Begin "+sql + " End; ";
     try{
     PreparedStatement pstat = conn.prepareStatement(sql);
for (int i=0; i<=j-1; i++ ){
int k = i+1;
pstat.setObject(k, arrayValues);
     ResultSet rset = pstat.executeQuery();
     rset.close();
     pstat.close();
catch (Exception e) {
System.err.println(e);
System.out.print("sql " + sql);
System.exit(1);
table_name_2 = table_name;
thisElement = "";
public static void main (String args[]) {
XMLReader xmlReader = null;
System.out.println("Time " + new java.util.Date());
try {
SAXParserFactory spfactory = SAXParserFactory.newInstance();
spfactory.setValidating(false);
SAXParser saxParser = spfactory.newSAXParser();
xmlReader = saxParser.getXMLReader();
xmlReader.setContentHandler(new SurveyReader());
xmlReader.setErrorHandler(new SurveyReader());
InputSource source = new InputSource("short.xml");
xmlReader.parse(source);
conn.close();
} catch (Exception e) {
System.err.println(e);
System.exit(1);
This parser takes 2 hours to laod file of size around 8MB.
ANy suggestions on improving performance of the parser.
ANy other approach I should be taking to load this file into DB.
We are using ORacle 9i DB with Character set UTF 8.
Thanks!

String buf = (new String(ch, start, length)).trim();
if (thisElement != "root"){   
if ((buf.length() == 0) && (thisElement !="") ){
It run ok!
Thanks 58871!
Now, i want to export oracle table to xml file like :
<?xml version="1.0" encoding="UTF-8"?>
<root>
<emp>
<ename>aaa</ename>
<sal>3000</sal>
</emp>
<emp>
<ename>bbb</ename>
<sal>5000</sal>
</emp>
</root>
Can SAX export to xml format?
Pham Thanh Tung

Similar Messages

  • Loading XML file to BI 7

    Hi,
    I have a requirement to load XML file from Application server to BI 7. Most of the documents I saw online are related to BW 3.X.
    does any one have good examples of how this can be done in BI 7.
    thanks

    hi
    check the SAP documentation for loading XML file to BI
    http://help.sap.com/saphelp_nw70/helpdata/en/fe/65d03b3f34d172e10000000a11402f/frameset.htm

  • Loading xml file in ssis?

    what properties we need to set for loading xml file in to table?

    You need an XML file and an XSD. Some examples:
    http://blogs.msdn.com/b/mattm/archive/2007/12/11/using-xml-source.aspx
    http://microsoft-ssis.blogspot.com/2014/09/xsd-location-hardcoded-in-xml-source.html
    For more detailed answers, you need to be more specific with you question...
    Please mark the post as answered if it answers your question | My SSIS Blog:
    http://microsoft-ssis.blogspot.com |
    Twitter

  • Loading xml file and parsing error in web start

    Hello,
    I load a xml file from jar file, but i have a error at parsing see :
    ClassLoader cl= this.getClass().getClassLoader();
    File file = new File(cl.getResource("paradise/test/maquette/parser/areas.xml").getFile());
    parseur.parse(new InputSource(new FileInputStream(file)), this);
    the file opening but at parseur.parse() i have a path error with :
    http:// . . . . \Paradise_client\paradise.jar!\paradise\test\maquette\parser\areas.xml , bad name of directories .....
    Can you help me ? please :-(

    I need to do a similar thing but in my case I don't know the structure of the xml file. I have 2 questions for this mapping. For an xml file like this:
    <?xml version="1.0"?>
    <catalog>
    <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <genre>Computer</genre>
    <price>44.95</price>
    <publish_date>2000-10-01</publish_date>
    <publisher>Dummy Publisher Co.</publisher>
    <publisher_address>
    <city>London</city>
    <street>Heart St.</street>
    <no>23/5</no>
    </publisher_address>
    <description>An in-depth look at creating applications
    with XML.
    </description>
    </book>
    </catalog>
    If I'm right, I need to create a database named catalog and a table named book. But the problem comes out here: How can i store publisher_address? In a table or what? Other problem is, is there a difference between storing id attribute of the book and genre element of the book? I think they are just columns of the book table. But if I'm wrong what is the correct solution?

  • How to load XML files into ORACLE8i database?

    SAP data is being extracted into XML format (via IDOC) files which are being transferred to an ORACLE8i box. There will be a large amount of data transferred on a daily basis which will include updates and inserts. From all the information that I have read on this subject there are 2 options available :
    1. XML-SQL Utility - which converts XML into INSERT, UPDATE or DELETE SQL. There does not appear to be that much functionality available by this method for decodes, transformations on the input data.
    2. SQL*Loader - There was a statement in 1 piece of documentation stating that SQL*Loader could be used for loading XML format data files. I cannot however find any further information on how this is achieved or how it works.
    If anyone has any experience in loading XML format data files using either of the above methods (preferably SQL*Loader as it has more functionality) then could you please provide me with examples or guidance on this matter? Any help would be greatly appreciated as I am not familiar with XML format data files. I am from an Oracle 7.3 background but do not have much experience with Oracle 8 onwards.
    Disclaimer.
    Any views expressed in the above paragraphs are my own and not that of Hewlett Packard Ltd.

    We are loading XML into our database using CLOB datatypes. We don't use the XSU for inserts as it is too slow. We parse the incoming XML document into a PL/SQL record type and then build a generic insert. This might not work well if you have many tags to parse into columns. We also store the entire XML CLOB into a column without parsing the individual tags into separate columns. We then use Intermedia Text for fast, index-based searching within the XML column.
    Check out The Oracle XML Portal website for code examples on how to do this:
    www.webspedite.com/oracle

  • Most efficient way to load XML file data into tables

    I have a complex XML file running into MBs. I want to load it's data into 7-8 tables.
    Which way will be better:
    1) Use SQL Loader to actually load directly into the 7-8 tables directly by modifying the control card.
    Is this really possible and feasible? I am not even sure about it
    2) Load data as XML Type in a table and register it. Then extract from there to load into various tables.
    Please help. I have to find the most efficient way of doing it.
    Regards,
    Sudhir

    Yes it is possible to use SQL*Loader to parse and load XML, but that is not what it was designed for and so is not recommended. You also don't need to register a schema, just to load/store/parse XML in the DB either.
    So where does that leave you?
    Some options
    {thread:id=410714} (see page 2)
    {thread:id=1090681}
    {thread:id=1070213}
    Those talk some about storage options and reading in XML from disk and parsing XML. They should also give you options to consider. Without knowing more about your requirements for the effort, it is difficult to give specific advice. Maybe your 7-8 tables don't exist and so using Object Relational Storage for the XML would be the best solution as you can query/update tables that Oracle creates based off the schema associated to the XML. Maybe an External Table definition works better for reading the XML into the system because this process will happen just once. Maybe using WebDAV makes more sense for loading XML to be parsed (I don't have much experience with this, just know it is possible from what I've read on the forums). Also, your version makes a difference as you have different options available depending upon the version of Oracle.
    Hope all that helps as a starter.
    Edited by: A_Non on Jul 8, 2010 4:31 PM
    A great example, see the answers by mdrake in {thread:id=1096784}

  • How to load XML file to DB

    Hi All,
    My requirement is I have a XML file, its data should be stored in Database.
    Below is the sample XML file.
    <?xml version="1.0"?>
    <PaymentInfoMessageResponse>
    <PaymentInfoResponse>
    <TransactionType>940</TransactionType>
    <SequenceNum>04</SequenceNum>
    <CompanyCode>902</CompanyCode>
    </PaymentInfoResponse>
    <StatusCode>OK</StatusCode>
    <StatusDetail>OK</StatusDetail>
    <ResponseItemCount>2</ResponseItemCount>
    </PaymentInfoMessageResponse>
    I have a table with columns name say TransType,SeqNum
    the value 940,04 from XML file should be saved in TransType,SeqNum Column respectively
    I am using file adapter with native format builder,selecting file type as complex type and
    In design schema,I'm not able to proceed,i'm getting error in POP up as:
    Native Format builder:error
    No global elements exist.
    How can i proceed or any other way to load XML file to DB.
    urgent Help/suggestion is required.
    Thanks in advance

    HI all,
    1)If my input is .txt file.
    we can use file adapter,using native builder,sample it,
    delimited/fixed length, we can do normal file read and file write/DB write.It works fine.
    2)If my input file is xml file,we can't use native builder format(Because it doesn't support
    delimited/fixed length/complex character in native format builder).
    so,as said in the above reply,i took a sample XML file & converted to XSD using
    File Menu > New > All Technologies tab > General > XML > XML Schema from XML Document.
    It compiles fine.
    Now,if i use file adapter(read) -- BPEL -- File adapter(write).
    Inside Transform,i am mapping filereadVariable and filewrite Variable correctly.
    If my input file is Abc.xml and its contents in read file are:
    <?xml version="1.0"?>
    <PaymentInfoMessageResponse>
    <PaymentInfoResponse>
    <TransactionType>940</TransactionType>
    <SequenceNum>04</SequenceNum>
    <CompanyCode>902</CompanyCode>
    </PaymentInfoResponse>
    <StatusCode>OK</StatusCode>
    <StatusDetail>OK</StatusDetail>
    </PaymentInfoMessageResponse>
    In write folder,my contents are
    <PaymentInfoMessageResponse>
    <imp1:PaymentInfoResponse>
    <imp1:TransactionType/>
    <imp1:SequenceNum/>
    <imp1:ReceiptTime/>
    <imp1:CompanyCode/>
    </imp1:PaymentInfoResponse>
    <imp1:StatusCode/>
    <imp1:StatusDetail/>
    </PaymentInfoMessageResponse>
    Now,if i use file adapter(read) -- BPEL -- DB adapter(merge).
    Inside Transform,i am mapping filereadVariable and DBmerge Variable correctly.
    If my input file is Abc.xml and its contents in read file are:
    <?xml version="1.0"?>
    <PaymentInfoMessageResponse>
    <PaymentInfoResponse>
    <TransactionType>940</TransactionType>
    <SequenceNum>04</SequenceNum>
    <CompanyCode>902</CompanyCode>
    </PaymentInfoResponse>
    <StatusCode>OK</StatusCode>
    <StatusDetail>OK</StatusDetail>
    </PaymentInfoMessageResponse>
    My output in em console is like this.
    <CeStatementHeadersIntCollection>
    <top:CeStatementHeadersInt>
    <top:statementNumber/>
    <top:bankName/>
    </top:CeStatementHeadersInt>
    </CeStatementHeadersIntCollection>
    NO data is being inserted into DB.
    I can write my XMl file into write folder as it is using opaque object(No native format translation)
    I can write XML file into DB using BLOB data type.
    But my requirement is:
    I have a table with columns name say TransType,SeqNum
    the value 940,04 from above XML file should be saved in TransType,SeqNum Columns respectively.
    Can i do it using DOM parser/SAX parser?
    So any suggestion/help required
    Thanks in advance

  • 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.

  • Loading XML files into an 8.0.6 database...

    Hi,
    I've got an Oracle 8.0.6 instance (Sun E250 Solaris 5.7) with multiple import data feeds. I am currently using SQL*Loader to load this data which are flat text delimited files. My data feeds will soon be supplying XML files instead of these flat files which is great, unfortunately, I will not be able to upgrade in 8.1.7 in time so that I can use the XML parser.
    Is there anyway I can use SQL*Loader or some other tool to load XML files into my 8.0.6 database? If there is a way, could someone please send the information I would need to help perform this task?
    Thanks for all your help...
    Gerry D'Costa
    Database Administrator
    [email protected]
    12Snap.com

    Check out the Oracle XDB Developer's Guide, Chapter 3. There is an example of using BFileName function to load the xml files from a directory object created using create or replace directory. It works really well.
    Ben

  • How to load XML File to BW Delta Queue via Webpage

    Hello altogether,
    I am trying to load an CSV file via Webpage (the Webpage have to change the csv file in a xml/soap file) into BW Delta Queue.
    Steps that I have made:
    - Create an InfoSource
    - Create an BW Data Source with Soap Connection
    - Create an initial Delta without Data Transfer
    - Create a Web Service with TC - SE37 - Utilities -> More Utilities -> Create Web Service
    If I test the Web Service with TC - Soamanager (BW 7.0), the data entered here, are transferred to the BW Delta Queue.
    If I test the function module ( TC - SE37), the data also transferred to the Delta Queue.
    Now I think, that I have an error in the html file or the html file is not conform to the wsdl document?? Or should I have to create a virtual interface, but I don't find a possibility to creat it...???
    Can you please help me????
    The coding of the WSDL Document and the Website is attached (I can also send you the coding and error message via mail, if you want). Sorry I don't know how to display here the coding. I try it with symbol "click to display the text code", but afterwards I get an error message from the website...   So let me please know your mail address and I send it via mail....
    I hope, that somebody can help me!!!!!
    Edited by: Alina99 on Sep 8, 2009 11:44 AM
    Error Message from BW:
    ...sap-env:envelope..... soap-env:body><soap-env:fault><faultcode>soap-env:Client</faultcode></faultstring xml:lang="eng">Virtual Interface Method&gt;_-BI0_-QI6AZ_XML_APPL2_RFC::urn:sap-com:document:sap:soap:functions:mc-style&lt;not supported</faultstring>.......
    Edited by: Alina99 on Sep 8, 2009 11:56 AM

    Hello,
    I have done all the necessary config in BW. However, as I mentioned earlier, we are still not up with XI so I am trying to load XML to BW delta queue.  The question still remains, how do I make make the XML file (on my desktop say) point to the BW so the InfoPackage picks up and places in the delta queue?  Even if I had XI, there has to be a way whereby BW looks for the XML file.  That is what I want to know and stuck at.
    Any detailed step by step help will be appreciated as always.
    Cheers

  • Error while loading xml files using JDBC

    Hi,
    I am trying to load xml files into an xmltype table using JDBC calls and am getting this error for some files
    LPX-00200: could not convert from encoding UTF-8 to UCS2
    The xml files and our database are both UTF-8 encoded. The version of oracle that we have here is 9.2.0.6
    Any suggestions in this matter will be greatly appreciated.
    Thanks,
    Uma

    I also experienced this problem and unfortunately this solution didn't work for me given that the tag you suggested was already on the XML file.

  • Error while loading XML files into scott user

    Hi All,
    I'm new to xml files. I need to load xml files into database through OWB.
    I have xml file in my local machine & am trying to load into table PO of Scott. Scott is registered as repository user.
    Followed same steps as specified in userguide.
    But, when executing the procedure ( in two ways one as just table name, and other as user.table name) it is showing the below error:
    Procedure is:(1)--with username.tablename
    begin
    wb_xml_load(
    '<OWBXMLRuntime>'||
    '<XMLSource>'||
    '<file>&&SAMPLES_DIR.sample1.xml</file>'||
    '</XMLSource>'||
    '<targets>'||
    '<target dateFormat="yyyy.MM.dd">scott.PO</target>'||
    '</targets>'||
    '</OWBXMLRuntime>'
    end;
    ERROR at line 1:
    ORA-20006: Error occurred while truncating target database object SCOTT.PO.
    Base exception: ORA-01031: insufficient privileges
    ORA-06512: at "OWBSYS.WB_XML_LOAD_F", line 12
    ORA-06512: at "OWBSYS.WB_XML_LOAD", line 4
    ORA-06512: at "SCOTT.SAMPLE1", line 3
    ORA-06512: at line 1
    Procedure is:(2) with out username
    begin
    wb_xml_load(
    '<OWBXMLRuntime>'||
    '<XMLSource>'||
    '<file>&&SAMPLES_DIR.sample1.xml</file>'||
    '</XMLSource>'||
    '<targets>'||
    '<target dateFormat="yyyy.MM.dd">PO</target>'||
    '</targets>'||
    '</OWBXMLRuntime>'
    end;
    ERROR at line 1:
    ORA-20006: Error occurred while truncating target database object PO.
    Base exception: ORA-00942: table or view does not exist
    ORA-06512: at "OWBSYS.WB_XML_LOAD_F", line 12
    ORA-06512: at "OWBSYS.WB_XML_LOAD", line 4
    ORA-06512: at line 2
    xml file:
    <ROWSET>
    <ROW>
    <ID>100</ID>
    <ORDER_DATE>2000.12.20</ORDER_DATE>
    <SHIPTO_NAME>Adrian Howard</SHIPTO_NAME>
    <SHIPTO_STREET>500 Marine World Parkway</SHIPTO_STREET>
    <SHIPTO_CITY>Redwood City</SHIPTO_CITY>
    <SHIPTO_STATE>CA</SHIPTO_STATE>
    <SHIPTO_ZIP>94065</SHIPTO_ZIP>
    </ROW>     
    </ROWSET>
    Note: Everything works fine if I create PO table in OWBSYS user and execute the procedurein OWBSYS user. OWBSYS.PO table will be loaded.
    What privileges are missing, what shouldI do if I want to execute the procedure from scott user and load the table of scott.
    Thanks in advance for the help.
    Regards,
    Joshna

    Hi Joshna,
    Please follow below steps to load xml file to oracle database.
    1.First connect to owb (Design Center) through your repository owner user (ex : REP_OWNER).
    2. Import WB_XML_LOAD procedure . and exit to repository owner.
    3. connect to owb design center through your repository user (ex : REP_USER)
    Create New mapping and drag one Constant Operator and create one attribute, paste / edit following code
    '<OWBXMLRuntime>'||
    '<XMLSource>'||
    '<file>E:\SOURCE\emp.xml</file>'||
    '</XMLSource>'||
    '<targets>'||
    '<target truncateFirst = "FALSE" dateFormat="yyyy.MM.dd">rep_user.emp</target>'||
    '</targets>'||
    '</OWBXMLRuntime>'
    4. Drag pre mapping operator and select WB_XML_LOAD procedure
    5. Connect Constant Operator attribute to pre mapping operator.
    6. Drag two dummy tables and connect source to target. (ex : drag t1 (table) tab two times and connect.
    7. Validate and deploy the mapping.
    8. grant necessary grant command to rep_owner user to rep_user user.
    (Note : target truncateFirst = "FALSE" by default truncate the table. So you have to give grant privileges
    To rep_user , select ,insert, delete privileges.
    9. Execute the mapping , and check EMP table. (Note : before loading EMP table delete all records ).
    10 . If you want more description please go through the below link
    http://download.oracle.com/docs/html/A95931_01/apf.htm
    Regards
    Venkat

  • 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...

  • How to load XML files ? HELP!

    Hi folks.
    We have an old Oracle database 7.3..
    So we need to load XML files into its tables.
    As we understand Oracle Loader doesn't help us.
    Is the way to load that files?
    Thanks in advance
    Alex

    I know you realize 7.3 is old but this is sort of like trying trying to view a DVD when you only have a VCR. Simple answer would be buy a DVD player, i.e. upgrade to a more recent version of Oracle where you will get many features to handle XML.
    How do you want the XML loaded, all as a single object? That could be a CLOB column if 7.3 had them, I am not sure. You would probably have to write PL/SQL and something with UTL_FILE (if 7.3 had that) to load it.
    If you want to put it multiple columns based on its tags, you would be better off parsing it using PERL (or something) into a CSV and loading that in SQL*Loader.
    I assume as this is using XML it is a reasonably recent design, combining that with an ancient version of the database is just going to lead to endless headaches.

Maybe you are looking for