Extract Namespace using Extract variable policy

Hi All,

I need to extract namespace from a node to perform further operations. My XML is something like shown below.

<SOAP-ENV:Envelope 
     xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
     xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Header>...</SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <CreateAndSendEnvelope xmlns="http://www.docusign.net/API/3.0">....</CreateAndSendEnvelope>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I need to extract namespace of CreateAndSendEnvelope node.

I used extract variable policy as shown below.

  <XMLPayload>
      <Namespaces>
         <Namespace prefix="dir">http://schemas.xmlsoap.org/soap/envelope</Namespace>
      </Namespaces>
      <Variable name="operationname" type="string">
         <XPath>/dir:Envelope/dir:Body/CreateAndSendEnvelope/@xmlns</XPath>
      </Variable>
  </XMLPayload>

Any help would be appreciated,

Thankyou

Solved Solved
1 6 956
1 ACCEPTED SOLUTION

Namespaces in XML are very specific. The namespace often looks like a web URI, and we may assume that

http://foo/bar/

is equivalent to

http://foo/bar (no trailing slash)

But that is not the case, when dealing with XML namespaces.

Specific to your case, you have

<Namespaces>
  <Namespace prefix="dir">http://schemas.xmlsoap.org/soap/envelope</Namespace>
</Namespaces>

And that's not good. The namespace you want ends with a slash.

Add the trailing slash:

<Namespaces>
  <Namespace prefix="dir">http://schemas.xmlsoap.org/soap/envelope/</Namespace>
</Namespaces>


But, two additional things.

  1. if I were doing this I would not use "dir" as a prefix. It's true that the prefix is not semantically important. It's just a variable name. But as with regular programming code, there are good and bad variable names. When an xml namespace refers to the soap encoding namespace, the prefix used is often "soap". Or at the very least, 's'. That tells people what you intend.
  2. You can't get the xmlns via an attribute. you need to use the namespace-uri function

The result of these three changes like this:

  <XMLPayload>
    <Namespaces>
      <!-- note the trailing slash here -->
      <Namespace prefix="s">http://schemas.xmlsoap.org/soap/envelope/</Namespace>
    </Namespaces>
    <Variable name="operationname" type="string">
       <XPath>local-name(/s:Envelope/s:Body/*)</XPath>
    </Variable>
    <Variable name="xmlns" type="string">
       <XPath>namespace-uri(/s:Envelope/s:Body/*)</XPath>
    </Variable>

  </XMLPayload>

View solution in original post

6 REPLIES 6

ElangoD
Participant III

Hi,

Can u try with this line:

<Namespaces>
            <Namespace prefix="soapenv">http://schemas.xmlsoap.org/soap/encoding/</Namespace>
</Namespaces>
<Variable name="CreateAndSendEnvelope" type="string">
            <XPath>/soapenv:Envelope/soapenv:Header/soapenv:Header:Body/CreateAndSendEnvelope</XPath>
 </Variable>

No, that's not it.

hi, I can guess what the problem is, but YOU DIDN'T SAY IT.

You said "I need to extract namespace of CreateAndSendEnvelope node."

and "this is the policy I used"

and...

WHAT HAPPENED? What results did you see?

You didn't say.

I will have to guess. I guess that you didn't get the data extracted as you expected. Is that right?

Hi,

yes, I am unable to extract the value. operationname variable is Null

Namespaces in XML are very specific. The namespace often looks like a web URI, and we may assume that

http://foo/bar/

is equivalent to

http://foo/bar (no trailing slash)

But that is not the case, when dealing with XML namespaces.

Specific to your case, you have

<Namespaces>
  <Namespace prefix="dir">http://schemas.xmlsoap.org/soap/envelope</Namespace>
</Namespaces>

And that's not good. The namespace you want ends with a slash.

Add the trailing slash:

<Namespaces>
  <Namespace prefix="dir">http://schemas.xmlsoap.org/soap/envelope/</Namespace>
</Namespaces>


But, two additional things.

  1. if I were doing this I would not use "dir" as a prefix. It's true that the prefix is not semantically important. It's just a variable name. But as with regular programming code, there are good and bad variable names. When an xml namespace refers to the soap encoding namespace, the prefix used is often "soap". Or at the very least, 's'. That tells people what you intend.
  2. You can't get the xmlns via an attribute. you need to use the namespace-uri function

The result of these three changes like this:

  <XMLPayload>
    <Namespaces>
      <!-- note the trailing slash here -->
      <Namespace prefix="s">http://schemas.xmlsoap.org/soap/envelope/</Namespace>
    </Namespaces>
    <Variable name="operationname" type="string">
       <XPath>local-name(/s:Envelope/s:Body/*)</XPath>
    </Variable>
    <Variable name="xmlns" type="string">
       <XPath>namespace-uri(/s:Envelope/s:Body/*)</XPath>
    </Variable>

  </XMLPayload>

Thank you it worked !!!