Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 25th, 2008, 03:36 AM
Registered User
 
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with using AJAX in Mozilla

Hi!

I am reading an XML response in Mozilla. The response XML is like below:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<Categories>
<Category>
<CategoryId>4</CategoryId>
<CategoryName>Consultant</CategoryName>
<DepartmentId>11</DepartmentId>
</Category>
<Category>
<CategoryId>3</CategoryId>
<CategoryName>MST Program Development</CategoryName>
<DepartmentId>11</DepartmentId>
</Category>
<Category>
<CategoryId>2</CategoryId>
<CategoryName>MSTnet Testing</CategoryName>
<DepartmentId>11</DepartmentId>
</Category>
<Category>
<CategoryId>1</CategoryId>
<CategoryName>Videotape Training Project</CategoryName>
<DepartmentId>11</DepartmentId>
</Category>
</Categories>


I am trying follwoing code:

xmlHttp.responseXML.documentElement.childNodes[i-1].childNodes[1].text;

But in Mozilla, it is saying undefined. Whereas, it is coming in IE.
 
Old January 25th, 2008, 04:32 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Thats because according to the W3C DOM standard there is no .text property on a node.

The following should work:

xmlHttp.responseXML.documentElement.childNodes[i-1].childNodes[1].firstChild.nodeValue

That gets the nodeValue of the text node contained within the CategoryName node.

/- Sam Judson : Wrox Technical Editor -/
 
Old January 25th, 2008, 10:30 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

IE uses MSXML for XML parsing and the DOM implementation of MSXML has a property named text that is not standardized.
Mozilla follows the W3C DOM where the Level 3 Core DOM defines a property named textContent which you can use to access the text contents of an element node.
You should also be aware that accessing nodes by indexing the childNodes collection is error-prone in a cross-browser way as there are different ways white space text between elements is treated when building the DOM model. IE/MSXML ignore such white space while Mozilla includes it as text nodes so for instance with the following XML
Code:
<root>
  <foo>
    <bar>value</bar>
  </foo>
</root>
you can use xmlDocumentInstance.documentElement.firstChild to access the foo element with IE/MSXML while with Mozilla that expression accesses a text node with white space.
A better approach is to use getElementsByTagName or XPath to make sure you access only elements.






Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with ajax amit1me BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 September 28th, 2007 01:14 AM
Problem with Ajax angshujit ASP.NET 2.0 Basics 10 February 16th, 2007 03:40 AM
problem with ajax amit1me Ajax 2 January 16th, 2007 02:36 AM
The Mozilla & IE Problem webnitro HTML Code Clinic 8 January 19th, 2006 09:30 PM
alignment problem in IE and Mozilla rpalanivelu Javascript 2 November 17th, 2003 08:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.