locked
Convert XML to CSV RRS feed

  • Question

  • I am using the following code

    [xml]$inputFile=Get-Content"C:\temp\original_code_output.xml"  -EncodingUTF8
    $inputfile.Transaction.TXNHEAD |ConvertTo-Csv-NoTypeInformation-Delimiter";"|Set-Content-Path"C:\temp\CODE_OUTPUT.csv"-EncodingUTF8
    $inputfile.Transaction.TXNDETAIL |ConvertTo-Csv-NoTypeInformation-Delimiter";"|Add-Content-Path"C:\temp\CODE_OUTPUT.csv"-EncodingUTF8

    but got the following error

    ConvertTo-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
    At line:2 char:34
    + ... ion.TXNHEAD | ConvertTo-Csv -NoTypeInformation -Delimiter ";" | Set-C ...
    +                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidData: (:) [ConvertTo-Csv], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToCsvCommand

    Original XML file

    <?xml version="1.0" encoding="utf-8"?>
    <Problems>
      <Problem>
        <Rule>Microsoft.Rules.Data.SR0007</Rule>
        <ProblemDescription>Nullable columns can cause final results to be evaluated as NULL for the predicate.</ProblemDescription>
        <SourceFile>C:\temp\testing.sql</SourceFile>
        <Line>17</Line>
        <Column>7</Column>
        <Severity>Warning</Severity>
      </Problem>
      <Problem>
        <Rule>Microsoft.Rules.Data.SR0007</Rule>
        <ProblemDescription>Nullable columns can cause final results to be evaluated as NULL for the predicate.</ProblemDescription>
        <SourceFile>C:\temp\testing.sql</SourceFile>
        <Line>18</Line>
        <Column>5</Column>
        <Severity>Warning</Severity>
      </Problem>
    </Problems>


    • Edited by sakurai_db Tuesday, November 13, 2018 8:48 AM revise
    Tuesday, November 13, 2018 8:13 AM

All replies

  • Please do not post colorized code in this forum.  It is unreadable on most browsers.

    Please only post code using  the code posting tool provided.  Please edit your original post.

    Without the XML there is no way to answer your question.


    \_(ツ)_/

    Tuesday, November 13, 2018 8:21 AM
  • original post revised.
    Tuesday, November 13, 2018 8:48 AM
  • Please use the code posting tool provided on the edit bar "<>".


    \_(ツ)_/

    Tuesday, November 13, 2018 8:52 AM
  • Your XML does not match the code in any way.  Did you post the wrong XML?

    Please look closely at what you are posting.  Proper posting is critical to getting an answer. 


    \_(ツ)_/

    Tuesday, November 13, 2018 8:55 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee



    Just do it.

    Tuesday, November 27, 2018 2:35 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Tuesday, December 4, 2018 3:10 AM