PC Review


Reply
Thread Tools Rate Thread

ajax - Consuming .net web services from FireFox

 
 
Aidy
Guest
Posts: n/a
 
      4th Oct 2007
I couldn't find an ajax type group so I'll post here. It's a bit OT so feel
free to suggest a better group or web forum.

I've condensed the code below to illustrate the problem I'm having. I've
using the XPathEvaluator to query the returned XML The issue is that the
web service adds a namespace (xmlns="http://tempuri.org/) to the root node
and I can't get my code to work with it. The code below has two lines where
we set the text, one with the namesapce and one without. It works without
the namespace but not with. I think the solution is to do with the third
param of the evaluate method but I'm at a loss. Any ideas?

var parser=new DOMParser();

//var text = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ArrayOfWord
xmlns:xi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
xmlns=\"http://tempuri.org/\"><Word><ID>1</ID><Value>A</Value></Word><Word><ID>2</ID><Value>B</Value></Word></ArrayOfWord>";

var text = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ArrayOfWord
xmlns:xi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Word><ID>1</ID><Value>A</Value></Word><Word><ID>2</ID><Value>B</Value></Word></ArrayOfWord>";

var XmlDOM=parser.parseFromString(text,"text/xml");
var oEval = new XPathEvaluator();
var oResult = oEval.evaluate ('Word/Value', XmlDOM.documentElement, null, 0,
null);
if (oResult != null)
{
xel = oResult.iterateNext();
while (xel)
{
alert (xel.textContent);
xel = oResult.iterateNext();
}
}


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      4th Oct 2007
firefox follows the w3c standard for namespace support in xpath queries.
you need to supply a namespace resolver object that you pass to the
evaluate. something like:

var oResult = oEval.evaluate (
'Word/Value',
XmlDOM.documentElement,
{
normalResolver: XmlDom.createNSResolver(XmlDom.documentElement),
lookupNamespaceURI : function(p) {
switch(p) {
case 'xi;:
return "http://www.w3.org/2001/XMLSchema-instance";
case 'xsd':
return "http://www.w3.org/2001/XMLSchema";
default:
return this.normalResolver.lookupNamespaceURI(p);
}
}
},
0,
null);


your other option is to remove the namespace specs before loading the dom.

-- bruce (sqlwork.com)


Aidy wrote:
> I couldn't find an ajax type group so I'll post here. It's a bit OT so feel
> free to suggest a better group or web forum.
>
> I've condensed the code below to illustrate the problem I'm having. I've
> using the XPathEvaluator to query the returned XML The issue is that the
> web service adds a namespace (xmlns="http://tempuri.org/) to the root node
> and I can't get my code to work with it. The code below has two lines where
> we set the text, one with the namesapce and one without. It works without
> the namespace but not with. I think the solution is to do with the third
> param of the evaluate method but I'm at a loss. Any ideas?
>
> var parser=new DOMParser();
>
> //var text = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ArrayOfWord
> xmlns:xi=\"http://www.w3.org/2001/XMLSchema-instance\"
> xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
> xmlns=\"http://tempuri.org/\"><Word><ID>1</ID><Value>A</Value></Word><Word><ID>2</ID><Value>B</Value></Word></ArrayOfWord>";
>
> var text = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ArrayOfWord
> xmlns:xi=\"http://www.w3.org/2001/XMLSchema-instance\"
> xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Word><ID>1</ID><Value>A</Value></Word><Word><ID>2</ID><Value>B</Value></Word></ArrayOfWord>";
>
> var XmlDOM=parser.parseFromString(text,"text/xml");
> var oEval = new XPathEvaluator();
> var oResult = oEval.evaluate ('Word/Value', XmlDOM.documentElement, null, 0,
> null);
> if (oResult != null)
> {
> xel = oResult.iterateNext();
> while (xel)
> {
> alert (xel.textContent);
> xel = oResult.iterateNext();
> }
> }
>
>

 
Reply With Quote
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Consuming Web Services - Tutorial Mac Microsoft C# .NET 1 27th Jul 2006 06:06 AM
Problems Consuming Web Services bob garbados Microsoft ASP .NET 4 13th Oct 2004 10:35 PM
Services.exe still consuming 99% CPU Lem Lo Microsoft Windows 2000 Windows Updates 0 20th Feb 2004 05:12 AM
Consuming Web Services Pablo Salazar Microsoft C# .NET 1 6th Jan 2004 10:30 PM
Consuming XML Web Services from ASP.NET Tomas Deml Microsoft ASP .NET 0 10th Nov 2003 05:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:59 AM.