XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old February 8th, 2003, 08:44 PM
DarrenJ DarrenJ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 42 DarrenJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 21 sec
Reputation Power: 6
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

Reply With Quote
  #2  
Old February 10th, 2003, 09:24 PM
esosa esosa is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Mexicali Mexico
Posts: 23 esosa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to esosa
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.

Reply With Quote
  #3  
Old February 11th, 2003, 03:53 AM
DarrenJ DarrenJ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 42 DarrenJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 21 sec
Reputation Power: 6
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

Reply With Quote
  #4  
Old February 11th, 2003, 04:00 AM
a.koepke's Avatar
a.koepke a.koepke is offline
Second highest poster :p
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jul 2001
Posts: 7,323 a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 8 m 45 sec
Reputation Power: 27
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.

Reply With Quote
  #5  
Old February 11th, 2003, 04:55 AM
DarrenJ DarrenJ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 42 DarrenJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 21 sec
Reputation Power: 6
Quote:
Originally posted by a.koepke
The example posted would only work in IE since its using inbuilt IE functions.


Can you please explain little more about that. What IE functions are you reffering to? I'm a newbie you know...

Quote:
Originally posted by a.koepke
The link posted ^^^ is a really good reference.


Yeah, it's a great stuff...

Quote:
Originally posted by a.koepke
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.


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?

Reply With Quote
  #6  
Old February 11th, 2003, 05:00 AM
a.koepke's Avatar
a.koepke a.koepke is offline
Second highest poster :p
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jul 2001
Posts: 7,323 a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 8 m 45 sec
Reputation Power: 27
Quote:
I'll distibute this thing on the CDn so I can't use server side parsing


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.

Reply With Quote
  #7  
Old February 11th, 2003, 05:08 AM
DarrenJ DarrenJ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 42 DarrenJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 21 sec
Reputation Power: 6
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.

Reply With Quote
  #8  
Old February 11th, 2003, 10:09 AM
Eclipce Eclipce is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Sep 2000
Posts: 763 Eclipce User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 5 h 29 m 25 sec
Reputation Power: 0
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

Reply With Quote
  #9  
Old February 11th, 2003, 02:55 PM
DarrenJ DarrenJ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 42 DarrenJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 21 sec
Reputation Power: 6
Great links... Thanks!

Reply With Quote
  #10  
Old June 19th, 2003, 05:10 PM
bsuravar bsuravar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 2 bsuravar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #11  
Old June 20th, 2003, 11:47 AM
Ed Woychowsky Ed Woychowsky is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Pennsylvania
Posts: 6 Ed Woychowsky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool Make XML data islands work in Mozilla

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.

Reply With Quote
  #12  
Old June 20th, 2003, 01:07 PM
bsuravar bsuravar is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 2 bsuravar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #13  
Old June 21st, 2003, 09:12 AM
DarrenJ DarrenJ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 42 DarrenJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 21 sec
Reputation Power: 6
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.

Reply With Quote
  #14  
Old June 21st, 2003, 09:14 AM
DarrenJ DarrenJ is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 42 DarrenJ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 21 sec
Reputation Power: 6
I Forgott the zip file in my post above...
Attached Files
File Type: zip xmldom.zip (5.0 KB, 755 views)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XML/DOM - IE ws NS/Mozilla


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump