Change encoding of XML file

  • Hello Everyone,

    While parsing XML files in SSIS i am getting an error “Invalid character in given encoding”.

    I can overcome this issue by manually replacing first line of code

    <?xml version="1.0"?>

    With below line of code

    <?xml version="1.0" encoding="ISO-8859-1" ?>

    Does any one of you know how to change encoding in SSIS package by replacing first line of XML document? Or maybe you know some other, better solutions?

    As an example we can use just basic XML document with UTF-8 encoding (file attached)

    <?xml version="1.0"?>
    <MyNode>
    <ChildNode>TEST</ChildNode>
    </MyNode>

    Can anyone help?

    Can i provide anything to help you helping me?

    Regards

    Attachments:
    You must be logged in to view attached files.
  • I know nothing about this specific problem.

    But adding a Script Task to edit and save the file before onward processing should be straightforward. Can you write a little C#?

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • I can't unfortunately.

    So, script task is the way to go and C#.

    I see what i can do.

    Thank you!

  • This could also be done in Posh.

    Have a go and see how you get on. Feel free to post back ... if you cannot get this working, I will put something together for you.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • In the end i used powershell script like below to change Encoding to ASCII and that did the trick

     

    Get-ChildItem "PathToYourFolder" -Filter *.xml |

    ForEach-Object{

    $file=Get-Content $_.FullName

    $file | Set-Content -Encoding Ascii $_.FullName

    }

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply