473,509 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to read XML on web but can locally

If I do something like the following snippet in JS:

xFile = "test.xml";
xDoc = document.implementation.createDocument("", "theXdoc", null);
xDoc.load(xFile);

// there's a pause here then

var data = xDoc.getElementsByTagName("text1")[0];

It works locally in IE6 and MZ1 but doesn't work when I upload the files
MZ1 tells me that 'data' has no properties. What is it that I'm doing wrong?

Andrew Poulos

Jul 20 '05 #1
3 4785


Andrew Poulos wrote:
If I do something like the following snippet in JS:

xFile = "test.xml";
xDoc = document.implementation.createDocument("", "theXdoc", null);
xDoc.load(xFile);

// there's a pause here then

var data = xDoc.getElementsByTagName("text1")[0];

It works locally in IE6 and MZ1 but doesn't work when I upload the files
MZ1 tells me that 'data' has no properties. What is it that I'm doing
wrong?


Loading is done asynchronously so you need an onload event handler (for
Mozilla) and an onreadystate event handler for IE.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Martin Honnen wrote:


Andrew Poulos wrote:
If I do something like the following snippet in JS:

xFile = "test.xml";
xDoc = document.implementation.createDocument("", "theXdoc", null);
xDoc.load(xFile);

// there's a pause here then

var data = xDoc.getElementsByTagName("text1")[0];

It works locally in IE6 and MZ1 but doesn't work when I upload the
files MZ1 tells me that 'data' has no properties. What is it that I'm
doing wrong?

Loading is done asynchronously so you need an onload event handler (for
Mozilla) and an onreadystate event handler for IE.

I tried re-writing it to something like this for MZ:

<script type="text/javascript">

xmlDoc = "undefined";

function initXML(xmlFile) {
if (document.implementation&&document.implementation. createDocument) {
xmlDoc = document.implementation.createDocument("","doc",nu ll);
if (typeof xmlDoc != "undefined") {
xmlDoc.load(xmlFile);
xmlDoc.onload = stuffToDo;
}
}
}

function stuffToDo() {
alert(xmlDoc.getElementsByTagName("messages")[0]);
var msgobj = xmlDoc.getElementsByTagName("messages")[0];
// more stuff here...
}

</script>

<BODY onload="initXML('test.xml');">

The alert fires, so I think the xml file is being loaded, but it
displays the value as 'undefined'. It works locally so I'm at a loss as
to why it doesn't work when I post the files. Any help appreciated.

Andrew Poulos

Jul 20 '05 #3
Andrew Poulos wrote:
Martin Honnen wrote:


Andrew Poulos wrote:
If I do something like the following snippet in JS:

xFile = "test.xml";
xDoc = document.implementation.createDocument("", "theXdoc", null);
xDoc.load(xFile);

// there's a pause here then

var data = xDoc.getElementsByTagName("text1")[0];

It works locally in IE6 and MZ1 but doesn't work when I upload the
files MZ1 tells me that 'data' has no properties. What is it that I'm
doing wrong?


Loading is done asynchronously so you need an onload event handler
(for Mozilla) and an onreadystate event handler for IE.

I tried re-writing it to something like this for MZ:

<script type="text/javascript">

xmlDoc = "undefined";

function initXML(xmlFile) {
if (document.implementation&&document.implementation. createDocument) {
xmlDoc = document.implementation.createDocument("","doc",nu ll);
if (typeof xmlDoc != "undefined") {
xmlDoc.load(xmlFile);
xmlDoc.onload = stuffToDo;
}
}
}

function stuffToDo() {
alert(xmlDoc.getElementsByTagName("messages")[0]);
var msgobj = xmlDoc.getElementsByTagName("messages")[0];
// more stuff here...
}

</script>

<BODY onload="initXML('test.xml');">

The alert fires, so I think the xml file is being loaded, but it
displays the value as 'undefined'. It works locally so I'm at a loss as
to why it doesn't work when I post the files. Any help appreciated.

Andrew Poulos

I have a bit more info:
The following returns "HTML collection" for msgobj:
var msgobj = xmlDoc.getElementsByTagName("messages");

but "undefined" for
var msgobj = xmlDoc.getElementsByTagName("messages")[0];

To repeat, it works locally in MZ but fails when I post the file to the
server.

Andrew Poulos
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1725
by: Edelwater | last post by:
Hello, I have (possibly) a framework related problem Or VS specific : Error while trying to run the project: unable to start debugging on the server. could not start asp.net or atl debugging....
16
4173
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichč but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the...
2
1879
by: CM Manager via DotNetMonster.com | last post by:
I am very frustrated due to this exception error I am receiving. I've tried searching numerous user support groups, Microsoft Support Net, Google, etc. and haven't found exactly my situation....
3
2391
by: purkka | last post by:
Hi I replaced a Win 2000 Adv server to the Win 2003 Std with Front Page Server Extension and .Net Framework 2.0. FPSE is extended to Default Web Site. Visual Studio 2005: If I create a new web...
6
3612
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
3
2264
by: Michel Esber | last post by:
Hello, DB2 V8 LUW FP12 + Linux. I have just turned on DB2's connection concentrator feature. MAX_COORDAGENTS=1100 and MAX_CONNECTIONS=1500. Two hours after restarting the instance, the db...
10
5498
by: ron19ie | last post by:
Hi everyone, I have generated (using xsd) the c# code version of the report definition used for 2005 version of reports in reporting services. I was using it locally and I was able to deserialize...
6
8139
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
1
4262
by: rfarley | last post by:
Hi, I am using the pyserial module and am trying to read the serial port from an accelerometer (LIS302DL). It has an option in which you write "*debug\r\n" and then you read the data (three...
0
7136
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7344
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4730
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.