locked
Select node key value in XML using Power Shell RRS feed

  • Question

  • Fetch the key value in XML file.

    Below is the my input XML file and I would like to fetch the "bean/property/map/entry/dataAccess.name" value.

    (i,e : <entry key="dataAccess.name" value="C:\Users\vdhage\Desktop\DataLoader\extractLead.csv"/> value in below XML.)

    <bean id="csvAccountExtractProcess" class="com.salesforce.dataloader.process.ProcessRunner" singleton="false">
      <description>csvAccountExtract job gets Lead info from salesforce and saves info into a CSV file.</description>
      <property name="name" value="csvAccountExtractProcess"/>
      <property name="configOverrideMap">
        <map>
          <entry key="sfdc.debugMessages" value="false"/>
          <entry key="sfdc.debugMessagesFile" value="C:\Users\rgee\Desktop\DataLoader\commandlinelog.txt"/>      
          <entry key="sfdc.timeoutSecs" value="600"/>
          <entry key="sfdc.loadBatchSize" value="200"/>
          <entry key="sfdc.entity" value="Lead"/>
          <entry key="sfdc.extractionRequestSize" value="500"/>
          <entry key="sfdc.extractionSOQL" value="Select Id, Name FROM Lead Limit 2"/>
          <entry key="process.operation" value="extract"/>
          <entry key="dataAccess.type" value="csvWrite"/>
          <entry key="dataAccess.name" value="C:\Users\vdhage\Desktop\DataLoader\extractLead.csv"/>      
        </map>
      </property>
    </bean>
    Expected OUTPUT: C:\Users\vdhage\Desktop\DataLoader\extractLead.csv


    Wednesday, January 10, 2018 1:32 PM

All replies

  • $temp = @"
    <bean id="csvAccountExtractProcess" class="com.salesforce.dataloader.process.ProcessRunner" singleton="false">
      <description>csvAccountExtract job gets Lead info from salesforce and saves info into a CSV file.</description>
      <property name="name" value="csvAccountExtractProcess"/>
      <property name="configOverrideMap">
        <map>
          <entry key="sfdc.debugMessages" value="false"/>
          <entry key="sfdc.debugMessagesFile" value="C:\Users\rgee\Desktop\DataLoader\commandlinelog.txt"/>      
          <entry key="sfdc.timeoutSecs" value="600`"/>
          <entry key="sfdc.loadBatchSize" value="200"/>
          <entry key="sfdc.entity" value="Lead"/>
          <entry key="sfdc.extractionRequestSize" value="500"/>
          <entry key="sfdc.extractionSOQL" value="Select Id, Name FROM Lead Limit 2"/>
          <entry key="process.operation" value="extract"/>
          <entry key="dataAccess.type" value="csvWrite"/>
          <entry key="dataAccess.name" value="C:\Users\vdhage\Desktop\DataLoader\extractLead.csv"/>      
        </map>
      </property>
    </bean>
    "@
    $xml = [xml]$temp
    Write-Output ($xml.bean.property.map.entry | ?{$_.key -eq "dataAccess.name"}).Value
    

    • Proposed as answer by KLVSagar Wednesday, January 10, 2018 1:51 PM
    Wednesday, January 10, 2018 1:47 PM
  • [xml]$xml= @'
    <bean id="csvAccountExtractProcess" class="com.salesforce.dataloader.process.ProcessRunner" singleton="false">
      <description>csvAccountExtract job gets Lead info from salesforce and saves info into a CSV file.</description>
      <property name="name" value="csvAccountExtractProcess"/>
      <property name="configOverrideMap">
        <map>
          <entry key="sfdc.debugMessages" value="false"/>
          <entry key="sfdc.debugMessagesFile" value="C:\Users\rgee\Desktop\DataLoader\commandlinelog.txt"/>      
          <entry key="sfdc.timeoutSecs" value="600"/>
          <entry key="sfdc.loadBatchSize" value="200"/>
          <entry key="sfdc.entity" value="Lead"/>
          <entry key="sfdc.extractionRequestSize" value="500"/>
          <entry key="sfdc.extractionSOQL" value="Select Id, Name FROM Lead Limit 2"/>
          <entry key="process.operation" value="extract"/>
          <entry key="dataAccess.type" value="csvWrite"/>
          <entry key="dataAccess.name" value="C:\Users\vdhage\Desktop\DataLoader\extractLead.csv"/>      
        </map>
      </property>
    </bean>
    '@
    # [xml]$xml=Get-Content file.xml
    $xml.SelectSingleNode('//entry[@key="dataAccess.name"]').Value


    \_(ツ)_/

    Wednesday, January 10, 2018 5:37 PM