tags:

views:

349

answers:

1

Hi!

The webservice I've build returns XML by default, I added my own XML nodes which I need to query in a different application (Nintex). I do that with Xpath. But I can't seem to get the result I want...

    public class Service1 : System.Web.Services.WebService
{
    public struct aduser
    {
        public String result;
        public String username;
        public String email;
        public String password;
    }

    [WebMethod]
    public aduser CreateADUser(string domain, ...

    ...
    ...
    ...

    user.result = "Succes";
    user.username = loginName;
    user.email = emailAddress;
    user.password = password;

    return user;
}

The result I get is

<xml>
    <result xmlns="http://dev01/"&gt;Succes&lt;/result&gt;
    <username xmlns="http://dev01/"&gt;test0101&lt;/username&gt;
    <email xmlns="http://dev01/"&gt;[email protected]&lt;/email&gt;
    <password xmlns="http://dev01/"&gt;somepassword&lt;/password&gt;
</xml>

so when I try to extract for example the result value by doing /xml/result It does not work, I can't read out the value or do debugging because Nintex won't let me... I've tried a lot of different xpath queries but none give the result I want, any idea what I'm doing wrong?

This is probably a rookieproblem but I'm really stuck here :-(

+3  A: 

I don't know anything about Nintex products but your problem is you need to inform whatever XPath processor you are using about the "http://dev01/" namespace.

Typically this is done by using a namespace manager object and associating an XPath processor or passing as a parameter when executing the XPath.

The namespace manager holds a list of namespaces and the aliases being used for them. So in this example you could associate the aliaes 'a' with "http://dev01/". Your XPath would become:- /xml/a:result.

By way of an idea here is what it would look like in C# (how port this to your Nintex tool I don't know).

XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("a", "http://dev01/");
XmlNode resultNode = doc.SelectSingleNode("/xml/a:result", nsmgr);
AnthonyWJones
thnx for the answer, I'm gonna try to build this in my app!
Erik404