Import xml file

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Ayesha Yasmin Ayesha Yasmin 3 weeks, 3 days ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #53638
    Profile photo of Ayesha Yasmin
    Ayesha Yasmin
    Participant

    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
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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
    Profile photo of Ayesha Yasmin
    Ayesha Yasmin
    Participant

    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
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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
    Profile photo of Ayesha Yasmin
    Ayesha Yasmin
    Participant

    Thank so much for the explanation!!It helped 🙂

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

You must be logged in to reply to this topic.