473,725 Members | 2,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HELP: Parsing XML fails under frames...

I've written a simple javascript page that parses an XML file...
(Actually I just modified the "Parsing an XML File" sample from
http://www.w3schools.com/dom/dom_parser.asp)

The page works great standalone... but when I try to make this work
under frames I get "Error: Object required" when the following line
executes:
xmlDoc.getEleme ntsByTagName("t o")[0];

The standalone file is named treeView.htm (attached). You should be
able to copy and paste this into a simple editor, save it then open it
without (javascript) problems. The xml file is named note.xml and is
attached below. Finally, I've also attached the mainFrame.htm that I'm
trying to tie this together with... save it to the same folder as the
other two documents to replicate the "...Object required" error.

Can anyone tell me what's going on here? Further, I've noticed that my
styles work great stand-alone but fail under frames.

Any help would be appreciated.
celoftis
Code follows:
*************** ******treeView. htm************ *******
<html>
<head>
<title>TreeView </title>
<!--<script type="text/javascript" src="treeDecor. js"></script>-->
<script type="text/javascript">
var currentNode="";
var previousNode="" ;
var xmlDoc;
function debugTest() {
alert(xmlDoc.to String());
var span_to = document.getEle mentById("to");
if (span_to) {
alert("span_to found");
} else {
alert("span_to null");
}
var xdoc = xmlDoc
if (xmlDoc) {
alert("xmlDoc found");
} else {
alert("xmlDoc null");
}
var xmlObj = xmlDoc.getEleme ntsByTagName("t o");
if (xmlObj) {
alert("xmlObj found");
} else {
alert("xmlObj null");
}
alert("number of \"to\" elements found: " +
xmlDoc.getEleme ntsByTagName("t o").length);
//HERE IS THE ERROR!
var xmlObj2 = xmlDoc.getEleme ntsByTagName("t o")[0];
if (xmlObj2) {
alert("xmlObj2 found");
} else {
alert("xmlObj2 null");
}
var xmlObj3 =
xmlDoc.getEleme ntsByTagName("t o")[0].childNodes[0];
if (xmlObj3) {
alert("xmlObj3 found");
} else {
alert("xmlObj3 null");
}
var xmlObj4 =
xmlDoc.getEleme ntsByTagName("t o")[0].childNodes[0].nodeValue;
if (xmlObj4) {
alert("xmlObj4 found");
} else {
alert("xmlObj4 null");
}
}
function loadXML() {
//load xml file
// code for IE
if (window.ActiveX Object) {
xmlDoc=new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.async=fa lse;
xmlDoc.load("no te.xml");
getMessage();
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.imple mentation &&
document.implem entation.create Document) {

xmlDoc=document .implementation .createDocument ("","",null) ;
xmlDoc.load("no te.xml");
xmlDoc.onload=g etMessage;
} else {
alert('Your browser cannot handle this script');
}
}

function getMessage() {
debugTest();
document.getEle mentById("to"). innerHTML=xmlDo c.getElementsBy TagName("to")[0].childNodes[0].nodeValue;

document.getEle mentById("from" ).innerHTML=xml Doc.getElements ByTagName("from ")[0].childNodes[0].nodeValue;

document.getEle mentById("messa ge").innerHTML= xmlDoc.getEleme ntsByTagName("b ody")[0].childNodes[0].nodeValue;

document.getEle mentById("headi ng").innerHTML= xmlDoc.getEleme ntsByTagName("h eading")[0].childNodes[0].nodeValue;
} //getMessage

function navigateUrl(ful lName) {
if (currentNode==f ullName) { //do nothing when clicked on
same node
document.getEle mentById("statu s").innerHTML=" Click
ignored! (<b>"+fullName+ "</balready active)";
} else { //navigate to the new node...
document.getEle mentById("statu s").innerHTML=" "; //reset
status...
//set the current node to have a navy background

document.getEle mentById(fullNa me).style.cssTe xt="background-color:
#4488DD; /*color: green;*/text-decoration: underline; /*font-weight:
bold;*/";

document.getEle mentById(fullNa me).className=" currentNode";
previousNode=cu rrentNode;
document.getEle mentById("prevN ode").innerHTML ="Previous
node=<b>"+previ ousNode+"</b>";
currentNode=ful lName;
document.getEle mentById("currN ode").innerHTML ="Current
node=<b>"+curre ntNode+"</b>";
if (previousNode== '') { //no styles to change...
} else { //indicate that the previous slide has been
viewed...

document.getEle mentById(previo usNode).classNa me="visited";
}
}
} //end navigateUrl

function nodeHoverOn(ful lName) {
if (fullName==curr entNode) {
} else {

document.getEle mentById(fullNa me).style.cssTe xt="background-color:
#FFFFFF; /*color: green; */text-decoration: underline; /*font-weight:
bold;*/";
}
} //end nodeHoverOn

function nodeHoverOff(fu llName) {
document.getEle mentById(fullNa me).style.cssTe xt="";
//remove inline style.... cascades back to internal, or external css
} //end nodeHoverOff
</script>
<style>
div,span {
color: black;
cursor: pointer;
}

..notVisited {
text-decoration: none;
background-color: transparent;
}

..visited {
text-decoration: none;
background-color: InactiveBorder;
}

..currentNode {
text-decoration: underline;
background-color: #4488DD;
}

</style>
</head>
<body onload="loadXML ()" scroll=no>
<div id="node1" title="Question 1" onclick="naviga teUrl(this.id)"
class="notVisit ed" onmouseover="wi ndow.status=''; nodeHoverOn(thi s.id)"
onmouseout="win dow.status=''; nodeHoverOff(th is.id)">
To:&nbsp;<span id="to">Init value</span>
</div>
<div id="node2" title="Slide 2" onclick="naviga teUrl(this.id )"
class="offclass " onmouseover="wi ndow.status=''; nodeHoverOn(thi s.id)"
onmouseout="win dow.status=''; nodeHoverOff(th is.id)">
From:&nbsp;<spa n id="from">Init value</span>
</div>
<div id="node3" title="Objectiv es" onclick="naviga teUrl(this.id)"
class="offclass " onmouseover="wi ndow.status=''; nodeHoverOn(thi s.id)"
onmouseout="win dow.status=''; nodeHoverOff(th is.id)">
Subject:&nbsp;< span id="heading">In it value</span>
</div>
<div id="node4" title="End of Course"
onclick="naviga teUrl(this.id)" class="offclass "
onmouseover="wi ndow.status=''; nodeHoverOn(thi s.id)"
onmouseout="win dow.status=''; nodeHoverOff(th is.id)">
Message:&nbsp;< span id="message">In it value</span>
</div>
<br />
<div id="currNode">
</div>
<div id="prevNode">
</div>
<br />
<div id="status" style="backgrou nd-color: InactiveBorder" ></div>
</body>
</html>
*************** *************** *************** *************
*************** *****note.xml** *************** ************
<?xml version="1.0" encoding="iso-8859-1" ?>
<!-- Edited with XML Spy v2007 (http://www.altova.com) -->
<note time="12:03:46" >
<to>Tove</to>
<from>Jani</from>
<heading>Remind er</heading>
<body>Don't forget me this weekend!</body>
</note>
*************** *************** *************** *************
*************** **mainFrame.htm *************** ********
<html>
<head ></head>
<frameset id="mainFrame" cols="33%, *">
<frame title="TreeView " id="tv" name="tv"
src=XMLDOMParsi ng_treeview.htm/>
<frame title="Content" id="showframe" name="showframe " />
</frameset>
</html>
*************** *************** *************** *************** *

Jan 12 '07 #1
2 2102

hzgt9b schrieb:
I've written a simple javascript page that parses an XML file...
(Actually I just modified the "Parsing an XML File" sample from
http://www.w3schools.com/dom/dom_parser.asp)

The page works great standalone... but when I try to make this work
under frames I get "Error: Object required" when the following line
executes:
xmlDoc.getEleme ntsByTagName("t o")[0];

The standalone file is named treeView.htm (attached). You should be
able to copy and paste this into a simple editor, save it then open it
without (javascript) problems. The xml file is named note.xml and is
attached below. Finally, I've also attached the mainFrame.htm that I'm
trying to tie this together with... save it to the same folder as the
other two documents to replicate the "...Object required" error.

Can anyone tell me what's going on here? Further, I've noticed that my
styles work great stand-alone but fail under frames.

Any help would be appreciated.
celoftis
Code follows:
*************** ******treeView. htm************ *******
<html>
<head>
<title>TreeView </title>
<!--<script type="text/javascript" src="treeDecor. js"></script>-->
<script type="text/javascript">
var currentNode="";
var previousNode="" ;
var xmlDoc;
function debugTest() {
alert(xmlDoc.to String());
var span_to = document.getEle mentById("to");
if (span_to) {
alert("span_to found");
} else {
alert("span_to null");
}
var xdoc = xmlDoc
if (xmlDoc) {
alert("xmlDoc found");
} else {
alert("xmlDoc null");
}
var xmlObj = xmlDoc.getEleme ntsByTagName("t o");
if (xmlObj) {
alert("xmlObj found");
} else {
alert("xmlObj null");
}
alert("number of \"to\" elements found: " +
xmlDoc.getEleme ntsByTagName("t o").length);
//HERE IS THE ERROR!
var xmlObj2 = xmlDoc.getEleme ntsByTagName("t o")[0];
if (xmlObj2) {
alert("xmlObj2 found");
} else {
alert("xmlObj2 null");
}
var xmlObj3 =
xmlDoc.getEleme ntsByTagName("t o")[0].childNodes[0];
if (xmlObj3) {
alert("xmlObj3 found");
} else {
alert("xmlObj3 null");
}
var xmlObj4 =
xmlDoc.getEleme ntsByTagName("t o")[0].childNodes[0].nodeValue;
if (xmlObj4) {
alert("xmlObj4 found");
} else {
alert("xmlObj4 null");
}
}
function loadXML() {
//load xml file
// code for IE
if (window.ActiveX Object) {
xmlDoc=new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.async=fa lse;
xmlDoc.load("no te.xml");
getMessage();
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.imple mentation &&
document.implem entation.create Document) {

xmlDoc=document .implementation .createDocument ("","",null) ;
xmlDoc.load("no te.xml");
xmlDoc.onload=g etMessage;
} else {
alert('Your browser cannot handle this script');
}
}

function getMessage() {
debugTest();
document.getEle mentById("to"). innerHTML=xmlDo c.getElementsBy TagName("to")[0].childNodes[0].nodeValue;

document.getEle mentById("from" ).innerHTML=xml Doc.getElements ByTagName("from ")[0].childNodes[0].nodeValue;

document.getEle mentById("messa ge").innerHTML= xmlDoc.getEleme ntsByTagName("b ody")[0].childNodes[0].nodeValue;

document.getEle mentById("headi ng").innerHTML= xmlDoc.getEleme ntsByTagName("h eading")[0].childNodes[0].nodeValue;
} //getMessage

function navigateUrl(ful lName) {
if (currentNode==f ullName) { //do nothing when clicked on
same node
document.getEle mentById("statu s").innerHTML=" Click
ignored! (<b>"+fullName+ "</balready active)";
} else { //navigate to the new node...
document.getEle mentById("statu s").innerHTML=" "; //reset
status...
//set the current node to have a navy background

document.getEle mentById(fullNa me).style.cssTe xt="background-color:
#4488DD; /*color: green;*/text-decoration: underline; /*font-weight:
bold;*/";

document.getEle mentById(fullNa me).className=" currentNode";
previousNode=cu rrentNode;
document.getEle mentById("prevN ode").innerHTML ="Previous
node=<b>"+previ ousNode+"</b>";
currentNode=ful lName;
document.getEle mentById("currN ode").innerHTML ="Current
node=<b>"+curre ntNode+"</b>";
if (previousNode== '') { //no styles to change...
} else { //indicate that the previous slide has been
viewed...

document.getEle mentById(previo usNode).classNa me="visited";
}
}
} //end navigateUrl

function nodeHoverOn(ful lName) {
if (fullName==curr entNode) {
} else {

document.getEle mentById(fullNa me).style.cssTe xt="background-color:
#FFFFFF; /*color: green; */text-decoration: underline; /*font-weight:
bold;*/";
}
} //end nodeHoverOn

function nodeHoverOff(fu llName) {
document.getEle mentById(fullNa me).style.cssTe xt="";
//remove inline style.... cascades back to internal, or external css
} //end nodeHoverOff
</script>
<style>
div,span {
color: black;
cursor: pointer;
}

.notVisited {
text-decoration: none;
background-color: transparent;
}

.visited {
text-decoration: none;
background-color: InactiveBorder;
}

.currentNode {
text-decoration: underline;
background-color: #4488DD;
}

</style>
</head>
<body onload="loadXML ()" scroll=no>
<div id="node1" title="Question 1" onclick="naviga teUrl(this.id)"
class="notVisit ed" onmouseover="wi ndow.status=''; nodeHoverOn(thi s.id)"
onmouseout="win dow.status=''; nodeHoverOff(th is.id)">
To:&nbsp;<span id="to">Init value</span>
</div>
<div id="node2" title="Slide 2" onclick="naviga teUrl(this.id )"
class="offclass " onmouseover="wi ndow.status=''; nodeHoverOn(thi s.id)"
onmouseout="win dow.status=''; nodeHoverOff(th is.id)">
From:&nbsp;<spa n id="from">Init value</span>
</div>
<div id="node3" title="Objectiv es" onclick="naviga teUrl(this.id)"
class="offclass " onmouseover="wi ndow.status=''; nodeHoverOn(thi s.id)"
onmouseout="win dow.status=''; nodeHoverOff(th is.id)">
Subject:&nbsp;< span id="heading">In it value</span>
</div>
<div id="node4" title="End of Course"
onclick="naviga teUrl(this.id)" class="offclass "
onmouseover="wi ndow.status=''; nodeHoverOn(thi s.id)"
onmouseout="win dow.status=''; nodeHoverOff(th is.id)">
Message:&nbsp;< span id="message">In it value</span>
</div>
<br />
<div id="currNode">
</div>
<div id="prevNode">
</div>
<br />
<div id="status" style="backgrou nd-color: InactiveBorder" ></div>
</body>
</html>
*************** *************** *************** *************
*************** *****note.xml** *************** ************
<?xml version="1.0" encoding="iso-8859-1" ?>
<!-- Edited with XML Spy v2007 (http://www.altova.com) -->
<note time="12:03:46" >
<to>Tove</to>
<from>Jani</from>
<heading>Remind er</heading>
<body>Don't forget me this weekend!</body>
</note>
*************** *************** *************** *************
*************** **mainFrame.htm *************** ********
<html>
<head ></head>
<frameset id="mainFrame" cols="33%, *">
<frame title="TreeView " id="tv" name="tv"
src=XMLDOMParsi ng_treeview.htm/>
<frame title="Content" id="showframe" name="showframe " />
</frameset>
</html>
*************** *************** *************** *************** *
Better forget it if you want a croww-browser solution. I've tried it to
use an Iframe for HTTP requests and I wanted to use XML as response.
It's notpossible. IE 5/6 will open a dialog to save the XML file, IE 7,
too, but you can read out the dom source, and I remember that it was
quite difficult in Mozilla and Firefox. To read pure XML (and not text)
use native requests and nothing else.

Andi

Jan 12 '07 #2
Problem solved...
In the mainFrame.htm I added "runat=serv er" to the frames then
everything worked fine - too simple:

*************** **mainFrame.htm *************** ********
<html>
<head ></head>
<frameset id="mainFrame" cols="33%, *">
<frame runat=server title="TreeView " id="tv" name="tv"
src=XMLDOMParsi ng_treeview.htm/>
<frame runat=server title="Content" id="showframe"
name="showframe " />
</frameset>
</html>
*************** *************** *************** **************

Re: webEater:
I'm using javascript on the client and asyn calls to ASP.NET pages to
pull XML documents from the server w/o incident...

Jan 13 '07 #3

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

Similar topics

5
14059
by: Aleksandar Matijaca | last post by:
Hi there, I am in some need of help. I am trying to parse using the apache sax parser a file that has vaid UTF-8 characters - I keep end up getting a sun.io.MalformedInputException error. This is my code:
1
2965
by: martingerber | last post by:
Hi, I have the following script (javascript in html document): <html> <head> <meta http-equiv="content-type" content="text/html;charset=ISO-8859-1"> <title>Standort Speichern</title>
14
2165
by: TrvlOrm | last post by:
OK. After much playing around, I managed to get my frame page this far.. see code below. BUT...there are still errors with it, and what I would like to have happened is this: 1) On the Left Frame (File LeftEx8_2.html) a series of buttons, which when clicked prompt the user to enter information for background color, text color, link color, title and some text.
3
2464
by: djdave | last post by:
My problem is that i need an algorithm parse parse HTML. For an HTML page, my script has to parse all tags to get all forms values, even if there is frame, iframe, ... How can i do such a script ? Thanks
3
12081
by: Hilton Lima | last post by:
Hi there; I have the following problem. I am using one of the many javascript XML parsing scripts available around the Internet, but the parsing fails when it reach an XML child node that is empty, as in the example below: <FirstName>John</FirstName> <MiddleInitial></MiddleInitial> <LastName>Smith</LastName> John Smith does not have a middle initial. When the parsing scripts I tried reach this node, it fails with a message such as...
0
5571
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
7
2376
by: Donn Ingle | last post by:
Hi, I really hope someone can help me -- I'm stuck. I have written three versions of code over a week and still can't get past this problem, it's blocking my path to getting other code written. This might be a little hairy, but I'll try to keep it short. Situation: I want to pass a string to a function which will parse it and generate objects in a list.
8
1166
by: Tommy Grav | last post by:
I have a file with the format Field f29227: Ra=20:23:46.54 Dec=+67:30:00.0 MJD=53370.06797690 Frames 5 Set 1 Field f31448: Ra=20:24:58.13 Dec=+79:39:43.9 MJD=53370.06811620 Frames 5 Set 2 Field f31226: Ra=20:24:45.50 Dec=+78:26:45.2 MJD=53370.06823860 Frames 5 Set 3 Field f31004: Ra=20:25:05.28 Dec=+77:13:46.9 MJD=53370.06836020 Frames 5 Set 4
3
1013
by: Shawn Milochik | last post by:
> Regular expressions will do the trick nicely. Yes, but you'll probably have to look at each line three times or split it into a list and check the elements.
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8097
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.