This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Mozilla XML > August 2005 > Search elements with XPath
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 |
Search elements with XPath
|
|
| Eugene Prokopiev 2005-08-10, 8:54 pm |
| Hi,
I have this people.xml:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
targetNamespace="http://localhost:8080/wsapp/services/PeopleService"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:portType name="PeopleService">
<wsdl:operation name="add" parameterOrder="name sex age"/>
<wsdl:operation name="getList"/>
<wsdl:operation name="del" parameterOrder="id"/>
</wsdl:portType>
</wsdl:definitions>
How can I find all wsdl:operation which are childs of wsdl:portType
name="PeopleService"?
I wrote:
var doc = document.implementation.createDocument("","",null);
doc.async = false;
doc.load("people.xml");
var services =
doc.evaluate("/definitions/portType@name='PeopleService'/operations",
doc, "http://schemas.xmlsoap.org/wsdl/", XPathResult.ANY_TYPE, null);
while (services.iterateNext()) {
alert(operation[i].getAttribute("name"));
alert(operation[i].getAttribute("parameterOrder"));
}
But I got:
Error: uncaught exception: [Exception... "Could not convert JavaScript
argument arg 2 [nsIDOMXPathEvaluator.evaluate]" nsresult: "0x80570009
(NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame ::
file:///home/john/devel/xul/wsdl/wsdl.js :: analize :: line 4" data: no]
What's wrong?
--
Thanks,
Eugene Prokopiev
| |
| Eugene Prokopiev 2005-08-11, 7:23 am |
| Another code:
var doc = document.implementation.createDocument("","",null);
doc.async = false;
doc.load("people.xml");
var methods = doc.evaluate(
"/wsdl:definitions/wsdl:portType[@name='PeopleService']/wsdl:operation",
doc,
doc.createNSResolver(doc.documentElement),
XPathResult.ORDERED_NODE_ITERATOR_TYPE,
null
);
while (methods.iterateNext()) {
alert(methods.singleNodeValue);
}
On line with alert:
Error: uncaught exception: [Exception... "The expression cannot be
converted to return the specified type." code: "52" nsresult:
"0x805b0034 (NS_ERROR_DOM_TYPE_ERR)" location:
"file:///home/john/devel/xul/wsdl/wsdl.js Line: 13"]
What's wrong now?
--
Thanks,
Eugene Prokopiev
| |
| Axel Hecht 2005-08-11, 7:23 am |
| Eugene Prokopiev wrote:
> Another code:
>
> var doc = document.implementation.createDocument("","",null);
> doc.async = false;
> doc.load("people.xml");
> var methods = doc.evaluate(
> "/wsdl:definitions/wsdl:portType[@name='PeopleService']/wsdl:operation",
> doc,
> doc.createNSResolver(doc.documentElement),
> XPathResult.ORDERED_NODE_ITERATOR_TYPE,
> null
> );
> while (methods.iterateNext()) {
> alert(methods.singleNodeValue);
> }
>
singleNodeValue is only for UNORDERED_NODE_SNAPSHOT_TYPE or
ORDERED_NODE_SNAPSHOT_TYPE, you want to do
var node;
while ((node = methods.iterateNext())) {
alert(node);
}
Axel
| |
| Peter Van der Beken 2005-08-12, 7:51 pm |
| Eugene Prokopiev wrote:
> doc.evaluate("/definitions/portType@name='PeopleService'/operations",
> doc, "http://schemas.xmlsoap.org/wsdl/", XPathResult.ANY_TYPE, null);
> But I got:
>
> Error: uncaught exception: [Exception... "Could not convert JavaScript
> argument arg 2 [nsIDOMXPathEvaluator.evaluate]" nsresult: "0x80570009
> (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame ::
> file:///home/john/devel/xul/wsdl/wsdl.js :: analize :: line 4" data: no]
Maybe you should parse the error and read the spec: arg 2 in evaluate is
of type XPathNSResolver, which is either an object (which you could
create with createNSResolver) or a function mapping prefixes to uris,
not a string.
And XPath doesn't have the concept of a default namespace, which you
seem to be relying on here.
Peter
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|