PDA

View Full Version : xml abolute and relateive path


Shahzeb
11-21-2006, 07:24 AM
xml abolute and relateive path



Hi all

I got a little problem .... when I try to load xml using relative url "this.load("layout.xml")" its loaded and displayed on trace.. But when I give absolute path of xml e.g d:\layout.xml ... it does not an xml and showed this error............

No XML Loaded
Error opening URL "file:///D:\ayout.xml"

.. Below are the code of ths example.. Anyone can grab this problem out of dark..

---------------------------------------------------------------------------------------------
This work great !!!
---------------------------------------------------------------------------------------------

import mx.xpath.XPathAPI;
class LoadAbsoluteXML extends XML
{
var pathX,pathElm:String;
var xResArray:Array;


function LoadAbsoluteXML()
{
pathX = "layout.xml";
//pathX = "D:\layout.xml";
this.ignoreWhite = true;
this.load(pathX);
}

function onLoad(success:Boolean)
{
if(success)
{
pathElm = "/rootScreen";
xResArray = XPathAPI.selectNodeList(this.firstChild,pathElm);
trace(xResArray);
}
else
{
trace("No XML Loaded");
}
}
}

---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------


Not Work
---------------------------------------------------------------------------------------------
This doesn't work why I dont know!!!!!
---------------------------------------------------------------------------------------------

import mx.xpath.XPathAPI;
class LoadAbsoluteXML extends XML
{
var pathX,pathElm:String;
var xResArray:Array;


function LoadAbsoluteXML()
{
//pathX = "layout.xml";
pathX = "D:\layout.xml";
this.ignoreWhite = true;
this.load(pathX);
}

function onLoad(success:Boolean)
{
if(success)
{
pathElm = "/rootScreen";
xResArray = XPathAPI.selectNodeList(this.firstChild,pathElm);
trace(xResArray);
}
else
{
trace("No XML Loaded");
}
}
}

---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------

mcmcom
11-21-2006, 04:49 PM
you need to escape the "\" character in the path. try

pathX = "D:\\layout.xml";


hth,
mcm

Shahzeb
11-22-2006, 05:08 AM
no if I do like this it doesn't work

pathX = "D:\\layout.xml";


pathX = "D:\llayout.xml"; Means if i include more l then its work fine .....

and shows the path like this during debugging .... pathX = "D:\\layout.xml
.....

So weird I thnk I'd stop working on Action Script I'll switch on XAML, and WPF technology.... Action Script is not as mature as microsoft C#.. and other languages....

mcmcom
11-23-2006, 09:07 PM
it is a character escaping issue, try prefixing the literal string with a "@" like you can in C#. OR
try using a Url escaped version of "\"

hth,
mcm