![]() |
Problems accessing xml on localhost and access to getbytagname
Hello,
I am new to javascript coding and and am trying to access an xml doc on the localhost and write its contents to a div. The xml file is not formated as a hierarchical data file unfortunately but rather as html, i.e., <table>, <tr>, <td>, etc. tags. The data I'm trying to get to is in the <td> tags - see code below. So, I'm trying too access the xml doc, "parse" the dom, get to the values in the <td> tags, and write the table of data (from the xml file) to the targetDiv. Right now, nothing is happening when I click the input button, i.e., no errors, etc., nothing happens. Thanks for any help! Code:
<html> |
Quote:
|
And at least two usage errors, as well.
We *guarantee* you *ARE* getting errors...you are simply ignoring them. |
First - thanks very much for the replies!!!
Ok, now using the error console and I was getting at least one syntax error - added a missing curly bracket. Now I'm getting the following error but I'm not sure why the function is null or undefined or not an object. I defined it in the head of the document, etc. The xml file which it points to is there on the localhost in the path specified, so not sure what's up. SCRIPT5007: The value of the property 'getData' is null or undefined, not a Function object BTW, can you recommend a good free dev environment? Thanks!!!! Michael |
Show your code in its current state.
|
Code:
<html> |
I think it would be more important to see the XML he is trying to load.
As his code is written, it makes no sense: First, this line: Code:
x=xmlhttp.responseXML.documentElement.getElementsByTagName("<TD>");But then this line Code:
xx=x[i].getElementsByTagName("<TD>")Now, I grant you that is possible. XML such as: Code:
<TD>I want to see the XML. |
Ok, yes, my code may be a little screwy, but that's why I'm here :-) And, I do really appreciate the help!
Agreed, seeing the xml is probably a good idea, so I'm pasting it below..... I think it's not a "pretty" xml file or not formated as an xml data file should be, but it wasn't for me to choose. I just have to parse it and display the data in the tables (well, actually the contents of the whole file, but I'm starting with the data in the tables). Hopefully I can convince the client that they need to format the xml as xml data, etc. Code:
<html> |
You know, there may be an easier way to do this.
Since that *IS* HTML, don't even try to treat it as XML. Instead, put a HIDDEN <iframe> on your page and load the HTML in that <iframe>. Then you can just use HTML DOM methods in your JS code to grab the relevant data out of the <iframe>! |
True it is html and good/great suggestion! However, I have a couple objectives going on - 1st is to parse the file/data, but 2nd is to access xml on remote servers and parse the xml (albeit in this case html). I need to do both, access the file on a server, and parse it. I also have other objectives on the presentation or client-side, but right now, I'd like to pretend that this is an actual xml file on a server. Eventually my customer will produce an actual xml file (and I need to know how to do this in general), hopefully sooner rather than later.
So, wondering if you (all) can still help me figure out why my code isn't finding all the <td>'s and spitting them out onto the screen in the target div? The code is supposed to create an html table of the data in that xml(html) file. Thanks again! Michael |
Quote:
"some.xml" Code:
<xml>Code:
<!DOCTYPE HTML> |
Also, if by "remote servers" you mean servers OTHER than the one where the HTML page is running, you can't do that with JavaScript. JavaScript only allows you to access data from the SAME DOMAIN as the page running the script.
You would need to set up a proxy server on your own domain that fetched the remote data for you. Not hard to do, but can't be done with JS. |
Ok, sorry for the delay.....life etc., but i tried the code you provided and unfortunately it didn't work. The console reports that it's missing a ";" but I don't see where it should be - I mean, it looks like all of the ';' are in the right place.
??? Michael P.S. Thanks for the heads-up on accessing other servers via js! |
LogicAli's code in post #11 worked perfectly first time when I tried it.
Did you copy/paste it or type it in? To get usable copyable code from this silly forum, hit the "Quote" button on post #11 and then copy from the edit window that quotes the code. |
Success! Got it to work! Copy and pasted from the quote/editor. I had to edit the path to the data file to: "http://localhost/IIQ/some.xml".... Why would I have to specify the specific path if the the file, some.xml, was in the same directory as the index.html?
Will this code work on my original file that isn't formatted as xml (i.e., it's just html)? (I'll try it and see.) If you think it won't work, what can I do to get my original code to read the html file - basically to do what you did with this xml file? As always, thank you all! Michael |
| All times are GMT +1. The time now is 02:17 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.