1

I am trying to use a XML task in SSIS to get a session ID value from this XML:

<?xml version="1.0" encoding="utf-16"?>
<AuthenticationResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <authenticated xmlns="[link]">true</authenticated>
    <sessionId xmlns="[link]">0000-0000000-00000000000-000000</sessionId>
    <loginid xmlns="[link]">000000</loginid>
    <login_name xmlns="[link]">[Username]</login_name>
    <user_nbr xmlns="[link]">0000</user_nbr>
    <partition_id xmlns="[link]">3</partition_id>
    <is_parent_mail_user xmlns="[link]">0</is_parent_mail_user>
    <parent_user_id xmlns="[link]" />
    <user_id xmlns="[link]">[username]</user_id>
</AuthenticationResult>

However I cant get the task to return the Session ID

Task setup:

Operation Type: XPATH
SourceType: File connection
Source: testfile.xml

SaveOperationResult: True
DestinationType: Variable
Destination: User::SessionID
OverwriteDestination: True

SecondOperandType: Direct input
SecondOperand: //sessionId

Namespaces: (Collection)
PutResultsInOneNode: False
XPathOperation: Values

No name spaces are specified.

I have googled all around but I can't figure out why it is not working...

JasonBluefire
  • 312
  • 5
  • 14

1 Answers1

1

You can look at this answer for suggestions with XPath syntax. Basically you can make use of local-name() to read the element names without the namespace. You should be able to extract this session Id value with:

 <local name="sessionId"/>
 <xmltask source="${xml.file}">
    <copy path="/*[local-name()='AuthenticationResult']/*[local-name()='sessionId']/text()"
          property="sessionId"/>
 </xmltask>
 <echo message="sessionId = ${sessionId}"/>

Alternatively, the simplified syntax below might work:

 <xmltask source="${xml.file}">
    <copy path="//:AuthenticationResult/:sessionId/text()"
          property="sessionId"/>
 </xmltask>
Community
  • 1
  • 1
Patrice M.
  • 4,209
  • 2
  • 27
  • 36
  • 1
    That answer helped a lot, This as the Operand worked: /*/*[local-name()='sessionId'] Thanks – JasonBluefire Jul 16 '15 at 13:07
  • Great! I fixed a couple of syntax problems with my earlier answer, which might have accounted for them not working directly. I'm sorry about that, but hope someone else can use it. Thank you for accepting an imperfect answer. – Patrice M. Jul 16 '15 at 22:14