Click to See Complete Forum and Search --> : Javascript and XML
Nocturnal59
12-01-2003, 09:01 PM
Ok im trying to get the value from my xml file.
Here is what I have
external.js
function getRecords(docid,place)
{
var plate = new String();
var xmlPage = new String(docid);
var dest = new String(place);
var recordSet = window.document.getElementById(xmlPage).recordset("B");
window.document.getElementById(dest).innerHTML = recordSet;
alert(recordSet)
}
test.xml
<?xml version="1.0"?>
<BBLOCK>
<RENDER>
<A>test1</A>
<B>test2</B>
<C>test3</C>
<D>test4</D>
</RENDER>
</BBLOCK>
it works fine like that and i can dislplay my text fine on the page but when I have the xml sheet look like this it doent dislpay the value
<?xml version="1.0" standalone="yes" ?>
- <monitor>
<B connected="999" name="Unknown Soldier" kills="0" />
<B connected="29" name="Jinx&" kills="11" />
<B connected="58" name="johnnyawsome" kills="4" />
</monitor>
do i need a different method with getElementById??
Khalid Ali
12-01-2003, 09:36 PM
Take a look at this resource (http://www.webapplikations.com/pages/html_js/xml_js.html?menu_id=Web_sub)
These are all possible approaches with regard to XML and an http browser,
See the source I am sure you will find answer with a little work
Nocturnal59
12-01-2003, 09:43 PM
Khalid,
Is that the right link? It only has these links under javascript and xml.
DOM parsing IE specifc only.
IE XML data island example.
Work for NS developers for IE data island.
Direct approach - works for both IE and NS
Direct approach - DOM parsing NS6+ nd IE5+
None of which had anything to do with what i need.
I have also looked on about 3 other sites including
http://www.topxml.com/xml_dom/dom_object_methods.asp
and still cannot find my answer. Do you have any other links you can share. Thanks
Nocturnal59
12-01-2003, 09:48 PM
I have also tried to get it with
window.document.getElementById(xmlPage).getElementsByTagName("value").value;
and i keep getting undefined.
I am working with a locked xml page so i can't add ID tags. I think the easiest way would be to pull it up by the name, but i can't find a method to do it.
Khalid Ali
12-01-2003, 10:37 PM
See the thing is if you want some one to write the code for thats different story altogether,but they(links above) explore all possible ways to include...in a web page...that being said..
can you explain again what is it you really want ..post your XML file as well as your code and the results that you are expecting with the results/errors you are getting
Nocturnal59
12-01-2003, 10:54 PM
<monitor>
<details value="sd" name="type" />
</monitor>
I want to get the value of that element and dislpay it on my webpage
Here is the code that i have tried
.js file
function getRecords(docid,place)
{
var plate = new String();
var xmlPage = new String(docid);
var dest = new String(place);
var recordSet = window.document.getElementById(xmlPage).getElementsByTagName("type").value;
window.document.getElementById(dest).innerHTML = recordSet;
alert(recordSet)
}
.html file
<head>
<title>test</title>
</head>
<body>
<DIV ID="dfooter" style="position:relative;visibility:visible;"></DIV>
<XML ID="ID" src="p.xml" ondatasetcomplete="getRecords('ID','dfooter');" />
</body>
</html>
I have been searching for about 7 hours strait, and can not think of anything else to try. Well gonna go to sleep and try again tommorow
Nocturnal59
12-02-2003, 06:57 PM
I have been looking everywhere and still cannot find what i need. I think I might be getting a little closer but am not sure. Here is the newest code I have tried. If anyone can help out or let me know if I am getting any closer, it would be greatly appreciated. The error I am getting is undefined:
function getRecords(docid,place)
{
var plate = new String();
var xmlPage = new String(docid);
var dest = new String(place);
var recordSet = window.document.getElementById(xmlPage).getElementsByTagName("type").item(0).value;
window.document.getElementById(dest).innerHTML = recordSet;
alert(recordSet)
}
xml Page
<monitor>
<details value="sd" name="type" />
</monitor>
Nocturnal59
12-02-2003, 08:15 PM
ok, i was able to get my script working the way i want:
function getRecords(docid,place)
{
var plate = new String();
var xmlPage = new String(docid);
var dest = new String(place);
var recordSet = window.document.getElementById(xmlPage).childNodes(1).childNodes(window.document.getElementById(xmlP age).childNodes(1).childNodes.length - 1).getAttribute('value');
window.document.getElementById(dest).innerHTML = recordSet;
alert(recordSet)
}
but when I upload the files to my server nothing happens. It works fine locally but not on my server. You guys have any idea what i might be doing wrong?
Nocturnal59
12-02-2003, 08:29 PM
Sorry to keep posting and being annoying, but can someone test this page localy and then on a server? here is the page, you should get an alert when you run the page
<html>
<script language="javascript">
function getRecords(docid,place)
{
var plate = new String();
var xmlPage = new String(docid);
var dest = new String(place);
var recordSet = window.document.getElementById(xmlPage).childNodes(1).childNodes(window.document.getElementById(xmlP age).childNodes(1).childNodes.length - 1).getAttribute('value');
window.document.getElementById(dest).innerHTML = recordSet;
alert(recordSet)
}
</script>
<head>
<title>test</title>
</head>
<body>
<DIV ID="dfooter" style="position:relative;visibility:visible;"></DIV>
<XML ID="ID" src="http://www.serverspy.net/bin/smonXml.mpl?mid=39282" ondatasetcomplete="getRecords('ID','dfooter');" />
</body>
</html>
TheBearMay
12-03-2003, 07:46 AM
I haven't tried this yet, but the thing that comes to mind is cross domain. I had the same problem when working with RSS feeds from different domains, and had to tell my browser that my page was on a trusted site before it would allow the data to be accessed.
Nocturnal59
12-03-2003, 08:45 AM
Is there anyway aound this? I have tried include files, frames, but nothing seams to work. It works fine localy on my machine, but not on a server. When i copy the code from http://www.serverspy.net/bin/smonXml.mpl?mid=39282 and put it into a xml file like http://www.webek.com/p.xml i have no problem. I just emailed the to see if they can give me a feed to the xml file.
TheBearMay
12-03-2003, 08:52 AM
Short of lowering the security settings for that site I haven't found one.
Nocturnal59
12-03-2003, 01:55 PM
I am using a program called wget.exe to automaclty dl that file from the internet every minute. Then I am converting the file to .xml with a .bat file which also automaticly uploads it to my webpage. Pain in the ass, but the only way i can think of getting it to work