What to do with XML

Welcome Forums General PowerShell Q&A What to do with XML

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

 
Participant
5 years, 6 months ago.

  • Author
    Posts
  • #7928

    Participant
    Points: 1
    Rank: Member

    I have a custom ComObject that I connect to.  It has a property that I call.  It outputs in XML format.  From that point I'm curious what my options are for viewing this XML?  I'm familiar with reading XML files using get-content.  In this case, the XML is not in a file that get-content can work with.  So I guess that option is out?  I do not want to write the output of the ComObject's property to a file, but want to do something in Powershell with it to make it more readable.  Then maybe move it into a file.

  • #7929

    Participant
    Points: 1
    Rank: Member

    What type of object are you getting back from your property? Is it a System.Xml.XmlDocument? If so, you can reference the OuterXml property on that object to view the Xml document.

  • #7930

    Participant
    Points: 1
    Rank: Member

    What type of object are you getting back from your property? Is it a System.Xml.XmlDocument? If so, you can reference the OuterXml property on that object to view the Xml document.

    How can I tell what type of object it is coming back?  After I create the -ComObject, I'm calling it with $variable.property.  It outputs XML.

  • #7931

    Participant
    Points: 1
    Rank: Member

    It's likely that the XML is being returned as a text string instead of a PowerShell XML object. Try converting it by doing something like this: $xmlData = [xml]$variable.property. You should then be able to process $xmlData in exactly the same way as your imported xml files.

  • #7932

    Participant
    Points: 1
    Rank: Member

    It’s likely that the XML is being returned as a text string instead of a PowerShell XML object. Try converting it by doing something like this: $xmlData = [xml]$variable.property. You should then be able to process $xmlData in exactly the same way as your imported xml files.

    Wow!  That is slick!  Worked great.  Thank you very much.

The topic ‘What to do with XML’ is closed to new replies.