Import xml file

Welcome Forums General PowerShell Q&A Import xml file

This topic contains 4 replies, has 2 voices, and was last updated by

 
Participant
2 years, 2 months ago.

  • Author
    Posts
  • #53638

    Participant
    Points: 0
    Rank: Member

    Hi,

    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

    Member
    Points: 0
    Rank: Member

    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

      Participant
      Points: 0
      Rank: Member

      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

    Member
    Points: 0
    Rank: Member

    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

      Participant
      Points: 0
      Rank: Member

      Thank so much for the explanation!!It helped 🙂

The topic ‘Import xml file’ is closed to new replies.