Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Reference to undeclared namespace prefix: 'soapenv'.Helpful Member!(2) 

ddiamond (Programmer) (OP)
26 Jun 07 12:30
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="http://rebusis.com/webservices/gcs/IntegrationService" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

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.



Helpful Member!  tsuji (TechnicalUser)
27 Jun 07 4:36
>/soapenv:Envelope/soapenv:Body/*/name()
Should take out the parentheses if name is an element node of no namespace qualification?
/soapenv:Envelope/soapenv:Body/*/name
ddiamond (Programmer) (OP)
27 Jun 07 8:52
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="http://rebusis.com/webservices/gcs/IntegrationService" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <ProcessUW xmlns="http://rebusis.com/webservices/gcs/IntegrationService">
    </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?



Helpful Member!  k5tm (Programmer)
27 Jun 07 9:50

Quote:

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
www.liant.com

ddiamond (Programmer) (OP)
27 Jun 07 12:11

Quote:

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/*)




k5tm (Programmer)
27 Jun 07 13:02
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
www.liant.com

ddiamond (Programmer) (OP)
27 Jun 07 13:18
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 www.w3schools.com.

Quote:

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'.
k5tm (Programmer)
27 Jun 07 14:28
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
www.liant.com

tsuji (TechnicalUser)
28 Jun 07 4:03
[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.

oRequest.setProperty "SelectionLanguage", "XPath"
oRequest.setProperty "SelectioNamespaces", "xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"

(If there are more namespaces, just add to the value with space seperator.
tsuji (TechnicalUser)
28 Jun 07 4:33
typo
oRequest.setProperty "SelectionNamespaces", "xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
tsuji (TechnicalUser)
28 Jun 07 5:53
Amendment
Still some error slipped in there. A re-take!
    oRequest.setProperty "SelectionNamespaces", "xmlns:soapenv='http://www.w3.org/2003/05/soap-envelope'"
ddiamond (Programmer) (OP)
28 Jun 07 8:45
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  

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close