|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
XML/DOM - IE ws NS/Mozilla
Hello,
I'm trying to load an XML file with the JavaScript functions. File loads fine in IE, NS and Mozilla but output is wrong in NS and Mozilla. I hope that someone can help me solve this problem. XML-file (valid.xml): Code:
<?xml version="1.0"?>
<gallery>
<images>
<comment>Test text 0</comment>
</images>
<images>
<comment>Test text 1</comment>
</images>
<images>
<comment>Test text 2</comment>
</images>
<images>
<comment>Test text 3</comment>
</images>
<images>
<comment>Test text 4</comment>
</images>
</gallery>
javascript code: Code:
var myXML;
function begin() {
tmp = "";
tmp1 = "gallery";
myXML = jsXML.createDOMDocument(tmp, tmp1);
myXML.onreadystatechange = doLoad;
myXML.load("valid.xml");
}
function doLoad() {
if (myXML.readyState == 4) {
var root = myXML.documentElement;
// output starts here:
document.write("RootTag: <b>"+root.nodeName+"</b>. Number of childNodes: <b>"+root.childNodes.length+".</b><br><br>");
for (i = 0; i < root.childNodes.length; ++i){
document.write(root.childNodes[i].nodeName+": "+root.childNodes[i].text+"<br/>");
}
}
}
Function begin() is called from the body tag on page load. This is output I'm getting from IE: RootTag: gallery. Number of childNodes: 5. images: Test text 0 images: Test text 1 images: Test text 2 images: Test text 3 images: Test text 4 Everything is fine here... This is output I'm getting from NS/Mozilla RootTag: gallery. Number of childNodes: 11. #text: undefined images: undefined #text: undefined images: undefined #text: undefined images: undefined #text: undefined images: undefined #text: undefined images: undefined #text: undefined This isn't fine... Is there anyone that knows what may be the problem here? I for sure doesn't see anything wrong... Thanks in advance.
__________________
Best regards Darren |
|
#2
|
|||
|
|||
|
I am a newbie about XML and XSLT but I think that displaying XML on a page dynamically (like an XML data Island) only works on IE
If anybody knows a workaround, please post it. |
|
#3
|
|||
|
|||
|
You are right about data islands... They only works in IE. But what I use here is a cross browser javascript code that loads XML file with the load() command. Then I should be able to use DOM to read and retrive information from the XML file.
You can find a great tutorial for this script on http://www.webreference.com/program...pper/index.html |
|
#4
|
||||
|
||||
|
The example posted would only work in IE since its using inbuilt IE functions. The link posted ^^^ is a really good reference.
I personally would always try and use a server sided scripting language to do all my XML work and then pass the resulting HTML to the client. That way you dont need to worry about browsers. |
|
#5
|
|||||
|
|||||
|
Quote:
Can you please explain little more about that. What IE functions are you reffering to? I'm a newbie you know... Quote:
Yeah, it's a great stuff... Quote:
I'm stuck with the client side here because I'll distibute this thing on the CDn so I can't use server side parsing. Do you know some other example that I could use and that works in IE, NS and Mozilla? |
|
#6
|
||||
|
||||
|
Quote:
Since when? I made a VB wrapper that loaded Xitami from a CD and then loaded their default web browser. I had xitami setup on a non-standard port and it worked well. PHP runs from the CD file. In my sig you will see a link to the WABN Book of Lists. This web app is available on CD using this wrapper. As to IE specific functions: jsXML.createDOMDocument(tmp, tmp1); That ^^^ will only work in IE. That is what i was referring to. |
|
#7
|
|||
|
|||
|
As I said I'm a newbie...
Will check out your link.jsXML.createDOMDocument(tmp, tmp1) is actually call to another JavaScript function that checks if browser is IE or Mozilla based. Then it takes browser specific code and creates document. That part of the posted code is working. Problem is that I can't get values from the XML files to show in the NS/Mozilla. As you can see in the code above NS/Mozilla are displaying nodeName of my childNodes... But they refuse to display values. Say for example that my XML file is looking like this: Code:
<root>
<img>
<comment>some text</comment>
</img>
...
If I then check number of childNodes that <img> tag has, IE is reporting 1 and NS/Mozilla are reporting 3. I'm sure that I'm doing something wrong here but can't find it... Last edited by DarrenJ : February 11th, 2003 at 05:16 AM. |
|
#8
|
|||
|
|||
|
The reason is because IE's DOM and NS/Mozilla's DOM are not quite the same, nor are they acessed the same way.
Devshed has two good tutorials on the Mozilla DOM. Rough Guide to the DOM Eclipce
__________________
Baptism By The Scriptures | Fifty Objections to Baptism Answered | HTML Bible | God's Salvation Plan Lifetime Residual Income |
|
#9
|
|||
|
|||
|
Great links... Thanks!
|
|
#10
|
|||
|
|||
|
Finally did you get it working
Hi Darren,
Looked like you got it working. Could you please mail me the example of the wrapper for Mozilla? I am trying to do exactly what you have already done. Thanks, bhanu. URL |
|
#11
|
|||
|
|||
|
I wrote an article on subject of XML Data Islands in Mozilla (http://builder.com.com/article.jhtm...030515woy01.htm) last month. Hope this helps.
|
|
#12
|
|||
|
|||
|
I have gone through the article already but my interest is in using xslt transformation on the client end. Currently I use MSXML dom on IE and planning to support Mozilla, hence the requirement. Also note that doing server side transformation is not an option for this task.
Thanks, bhanu. |
|
#13
|
|||
|
|||
|
Hi Bhanu,
I'm attaching crossbrowser JS-wrapper to this message. You'll also find an example xml and html file. Just extract zip file and run dom6.html file to se wrapper in action. JS wrapper is made by Nicholas C. Zakas (http://www.nczonline.net/). On the other side if you want to use XSL transformation with possibility to send parameters to the stylesheet (on the client side) check out my second post in this thread: http://forums.devshed.com/t55051/s.html Let me know if you have any other questions. Last edited by DarrenJ : June 21st, 2003 at 10:26 AM. |
|
#14
|
|||
|
|||
|
I Forgott the zip file in my post above...
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XML/DOM - IE ws NS/Mozilla |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|