Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Professional Ajax ISBN: 978-0-471-77778-6
This is the forum to discuss the Wrox book Professional Ajax by Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett; ISBN: 9780471777786
Important: For the new 2nd edition of this book, please post here instead: [url="http://p2p.wrox.com/forum.asp?FORUM_ID=307"]http://p2p.wrox.com/forum.asp?FORUM_ID=307[/url]
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Ajax ISBN: 978-0-471-77778-6 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
  #1 (permalink)  
Old January 15th, 2007, 09:37 AM
Registered User
 
Join Date: Jan 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error with oNodes zXPath in chapter 4

Hi:

I like this book so far but hit a problem in chapter 4, "Cross-Browser XPath", p108.

In file "NameSpaceBooks.htm":

var oRoot = oXmlDom.documentElement;
var sXPath = "na:book/pub:name";
var oNodes = zXPath.selectNodes(oRoot, sXPath, sNameSpace);
if (oNodes.length > 0) {
alert(oNodes.length + " nodes selected with '" + sXPath + "'");
}

oNodes.length returns 0 for me.
The file NameSpaceBooks.htm shows as a blank page in both FF and IE.
NameSpaceBooks.xml is fine as far as I can tell.

I am using * JavaScript zXml Library * Version 1.0.2

Any advice appreciated.

Chung Wang

  #2 (permalink)  
Old January 15th, 2007, 10:33 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

There is a slight error in the book regarding how to set namespace mappings for zXml which should be fixed for the next print run.
You need something like:
Code:
var namespace1 = "<namespace URI for na here>";
var namespace2 = "<namespace URI for pub here>";
var oNamespaceMapper = {na: namespace1, pub: namespace2};
var oRoot = oXmlDom.documentElement;
var sXPath = "na:book/pub:name";
var oNodes = zXPath.selectNodes(oRoot, sXPath, oNamespaceMapper);
if (oNodes.length > 0)
{
  alert(oNodes.length + " nodes selected with '" + sXPath + "'");
}
You will need to replace the namespace declarations with the real ones.

--

Joe (Microsoft MVP - XML)


Similar Threads
Thread Thread Starter Forum Replies Last Post
error with chapter 7 jdz66 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 August 21st, 2006 05:19 PM
Parse error in error handler (Chapter 8) Funky Monk BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 August 6th, 2004 08:59 AM





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