Import xml file

This topic contains 4 replies, has 2 voices, and was last updated by  Ayesha Yasmin 1 year, 10 months ago.

  • Author
  • #53638

    Ayesha Yasmin


    I am getting the below error, when I try to import the file.

    PS D:\> import-clixml -path d:\process.xml
    Import-Clixml : Data at the root level is invalid. Line 2, position 1.
    At line:1 char:14
    + import-clixml <<<< -path d:\process.xml + CategoryInfo : NotSpecified: (:) [Import-Clixml], XmlException + FullyQualifiedErrorId : System.Xml.XmlException,Microsoft.PowerShell.Commands.ImportClixmlCommand

  • #53645

    Dave Wyatt

    What's in that file? Was it created by the Export-Clixml cmdlet? If it's just a general XML file, don't use Import-Clixml. Do this instead:

    [xml](Get-Content d:\process.xml)
    • #53647

      Ayesha Yasmin

      Hi Dave,

      I had used out-file to export the file in xml. So if I dont use export file, I should not use import-clixml? Please clarify

      gps |out-file d:\process.xml

  • #53653

    Dave Wyatt

    If you used Out-File, then it's not really an XML file at all, regardless of what file extension you gave it. 🙂 It'll just be a text file containing a table or list (whatever you'd have seen at the console if you hadn't piped to Out-File.)

    Export-Clixml and Import-Clixml are paired commands; the import reads files created by the export.

    You could have done this:

    gps | Export-Clixml d:\process.xml
    # and later:
    Import-Clixml d:\process.xml
    • #53664

      Ayesha Yasmin

      Thank so much for the explanation!!It helped 🙂

You must be logged in to reply to this topic.