Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference to undeclared namespace prefix: 'soapenv'. 2

Status
Not open for further replies.

ddiamond

Programmer
Apr 22, 2005
918
US
I am trying to get the following xpath expression to work:

Code:
/soapenv:Envelope/soapenv:Body/*/name()
I get the following error:
Unknown method.
/soapenv:Envelope/soapenv:Body/*/-->name()<--

I've often found that problems like this can be resolved by the following code (vbscript):
Code:
oRequest.setProperty "SelectionLanguage", "XPath"
oRequest is my xml document object.

After adding this, my xpath expression generates the following error: Reference to undeclared namespace prefix: 'soapenv'.

Here is the first line of my xml source file:
<soapenv:Envelope xmlns:int=" xmlns:soapenv=" xmlns:xsi="
Why does it not recognize soapenv as a valid name space? If I don't include the line setting the language to xpath, it does not complain about the namespace. It just does not recognize name() as a valid xpath function.
 
>/soapenv:Envelope/soapenv:Body/*/name()
Should take out the parentheses if name is an element node of no namespace qualification?
[tt]/soapenv:Envelope/soapenv:Body/*/name[/tt]
 
Name is an xpath function. It returns the name of the current node.

Here is the structure of my xml file:

<soapenv:Envelope xmlns:int=" xmlns:soapenv=" xmlns:xsi=" <soapenv:Body>
<ProcessUW xmlns=" </ProcessUW>
</soapenv:Body>
</soapenv:Envelope>

What I am trying to do is write an xpath expression that will return the name of the child node directly under <soapenv:Body>. In this case, I would want the xpath expression to return 'ProcessUW'. That is my soapMethod that I will be passing to a web service.

Here is a work around that I am currently using:
Code:
Set oXPathResult = oRequest.selectSingleNode("/soapenv:Envelope/soapenv:Body/*")
sSoapMethod = oXPathResult.nodeName
Can this be done with a single xpath expression instead of resorting to the DOM nodeName method?
 
an xpath expression that will return the name of the child node directly under <soapenv:Body>
In other words, you want to fetch the method name.

That would be:
Code:
name(/soapenv:Envelope/soapenv:Body/*)
if you want the entire name (including namespace), or:
Code:
local-name(/soapenv:Envelope/soapenv:Body/*)
if you want just the element name without the namespace.

Tom Morrison
 
In other words, you want to fetch the method name.
Tom, thanks for stating it so concisely. That is exactly what I am trying to do. I tried your xpath expression:
Code:
name(/soapenv:Envelope/soapenv:Body/*)
I got the following error message:
Unknown method.

-->name(/<--soapenv:Envelope/soapenv:Body/*)




 
I apologize for being unfamiliar with the procedural scripting language. Perhaps tsuji will help with that.

name() and local-name() are XPath functions defined in the XPath specification, so I do not have any idea about what may be interpreting name() as a method.

Tom Morrison
 
That error message is coming from microsofts xml parser, msxml. It indicates that it does not recognize that name is a xpath function. I've ran into this problem before, and the fix has always been to set the parser's language to "XPath". Below is an excerpt from
Note: IE5 and later has implemented that [0] should be the first node, but according to the W3C standard it should have been [1]!!

A Workaround!
To solve the [0] and [1] problem in IE5+, you can set the SelectionLanguage to XPath.

The following example selects only the first book node under the bookstore element:

xmlDoc.setProperty "SelectionLanguage", "XPath"
xmlDoc.selectNodes("/bookstore/book[1]")
Unfortunately, when I set the language "XPath" as in the example above, it complains about my undeclared namespace 'soapenv'.
 
I think I understand what is causing your problem, and your workaround is probably the correct approach (i.e. not a workaround after all).

You are using the DOM. The method selectNodes() expects an XPath expression that selects node(s). But the XPath name() function does not return a nodeset, but rather a scalar value as a string.

Tom Morrison
 
[1] When you want to return _directly_ the (quaified) name from the selectsinglenode method of DOMDocument, it is self contractory and bound to fail. The selectsinglenode method would always return object of type IDOMElement, never would it be a string, as q name.

[2] When you put setProperty on the SelectionLanguage (a "second-level" dom property) to XPath, you have to be more rigorous in the namespace. You've to setProperty of the SelectionNamespaces as well. (Setting these is a version-dependent thing of msxml2 core service.) Like this.
[tt]
oRequest.setProperty "SelectionLanguage", "XPath"
oRequest.setProperty "SelectioNamespaces", "xmlns:soapenv="[/tt]
(If there are more namespaces, just add to the value with space seperator.
 
tsuji,

Thanks so much for clearing everything up. I had assumed I could use the name function with XML DOM because it works fine in my xslt files, but I now understand why that won't work. Also thanks for showing me how to get around the undefined namespace error when setting the selectionLanguage to 'XPath'.

- Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top