This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > July 2005 > xpath contains() error





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author xpath contains() error
ruckus

2005-07-08, 11:28 pm

I'm trying to use an xpath expression to return nodes in an XML document that
I have loaded with Microsoft.XMLHTTP. Specifically, I'm trying to use the
xpath contains() function. However, when I run this function in IE 6 I get
the following error: Unknown Method -->contains(<--

So I've got two questions:
1. I've been trying to find out if the MSXML parser that comes with IE 6 can
handle this function or not, but have been unable to find this information. I
know that MSXML 2.0 does not have it and that MSXML 3.0 does, but cannot find
out which version of MSXML IE 5 & IE 6 come preinstalled with.

2. Being new to XPath and AJAX, I'm not exactly sure as to the advantages of
XPath beyond the fact that it is much more concise than iterating through the
xml document tree with a set of loops. Specifically, I'd be interested to
know if using XPath is any less processor intensive than parsing the document
tree.

Thanks in advance for any help you can give me.
Gadrin@gmail.com

2005-07-08, 11:28 pm

It might be handy for #1 for us to see your code that errors out.

Joe Fawcett

2005-07-09, 7:18 am

"ruckus" <ruckus@discussions.microsoft.com> wrote in message
news:B8EA7CA8-BF09-4AE9-9B26-E3ECEE4A04D4@microsoft.com...
> I'm trying to use an xpath expression to return nodes in an XML document that
> I have loaded with Microsoft.XMLHTTP. Specifically, I'm trying to use the
> xpath contains() function. However, when I run this function in IE 6 I get
> the following error: Unknown Method -->contains(<--
>
> So I've got two questions:
> 1. I've been trying to find out if the MSXML parser that comes with IE 6 can
> handle this function or not, but have been unable to find this information. I
> know that MSXML 2.0 does not have it and that MSXML 3.0 does, but cannot find
> out which version of MSXML IE 5 & IE 6 come preinstalled with.
>


Without seeing your code my best guess is you're using the obsolete Microsoft
draft version of transforms, namespace http://www.w3.org/TR/WD-xsl rather than
XSLT, http://www.w3.org/1999/XSL/Transform. Show some code and tell us what
parser your using.

> 2. Being new to XPath and AJAX, I'm not exactly sure as to the advantages of
> XPath beyond the fact that it is much more concise than iterating through the
> XML document tree with a set of loops. Specifically, I'd be interested to
> know if using XPath is any less processor intensive than parsing the document
> tree.
>
> Thanks in advance for any help you can give me.


Well it depends on the source document but in general once you get into the
declarative mind set it's much easier to do operations via XSLT, the code is
easier to understand and maintain. I've never seen figures for efficiency.

--

Joe (MVP - XML)

https://mvp.support.microsoft.com/p...E8-8741D22D17A5


ruckus

2005-07-11, 8:03 pm

Thanks for the insight Joe...you're both right, I should have added the code.
Here it is:

I start by loading an XML doc with the following active x object:
var varXMLDoc = new ActiveXObject( "Microsoft.XMLHTTP" );

The XML doc loaded contains lists of music videos with artists, titles, and
descriptions for each artist:
<root>
<item>
<artist>name</artist>
<title>title</title>
<desc>description</desc>
</item>
</root>

Once the XML is loaded, I save the responseXML into another object as
"this.objData". I then try to access all artist nodes containing the string
"a":
var varNodeList = this.objData.selectNodes( "//artist[contains(.,'a')]" );

The last step is where I run into the javascript error: Unknown Method
-->contains(<--

I know that I'm loading the XML correctly because I can run through it using
the DOM, but it would be much nice to condense this all down into one line of
code.
Thanks again in advance for any help you can offer me.
benjus

2005-07-15, 10:15 am

Try this:

1. Use MS XML 3 (required to use XPath). Change this line:
var varXMLDoc = new ActiveXObject( "Microsoft.XMLHTTP" );
to this:
var varXMLDoc = new ActiveXObject( "MSXML2.XMLHTTP" );

2. Add this line before the call to selectNodes:
this.objData.setProperty("SelectionLanguage", "XPath");
Joe Fawcett

2005-07-16, 7:29 pm

"ruckus" <ruckus@discussions.microsoft.com> wrote in message
news:00819734-F957-4CC4-BB9E-BF2A657B3769@microsoft.com...
> Thanks for the insight Joe...you're both right, I should have added the code.
> Here it is:
>
> I start by loading an XML doc with the following active x object:
> var varXMLDoc = new ActiveXObject( "Microsoft.XMLHTTP" );
>
> The XML doc loaded contains lists of music videos with artists, titles, and
> descriptions for each artist:
> <root>
> <item>
> <artist>name</artist>
> <title>title</title>
> <desc>description</desc>
> </item>
> </root>
>
> Once the XML is loaded, I save the responseXML into another object as
> "this.objData". I then try to access all artist nodes containing the string
> "a":
> var varNodeList = this.objData.selectNodes( "//artist[contains(.,'a')]" );
>
> The last step is where I run into the javascript error: Unknown Method
> -->contains(<--
>
> I know that I'm loading the XML correctly because I can run through it using
> the DOM, but it would be much nice to condense this all down into one line of
> code.
> Thanks again in advance for any help you can offer me.

Looks like you're using an older version of XPath as stated before. If msxml4 is
installed on your machine then use that:
var varXMLDoc = new ActiveXObject( "msxml2.xmlhttp.4.0");

if version 3 then:
var varXMLDoc = new ActiveXObject( "msxml2.xmlhttp.3.0");
you may then need to set the language:
var oDom = varXMLDoc.responseXML;
oDom.setProperty("SelectionLanguages", "XPath");


--

Joe (MVP - XML)

https://mvp.support.microsoft.com/p...E8-8741D22D17A5



ruckus

2005-07-18, 7:45 pm

Thanks for all of the help Joe.
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews