What to do with XML

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Lery Lery 3 years, 10 months ago.

  • Author
    Posts
  • #7928
    Profile photo of Lery
    Lery
    Participant

    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
    Profile photo of Poshoholic
    Poshoholic
    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
    Profile photo of Lery
    Lery
    Participant

    [quote=7929]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.[/quote]

    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
    Profile photo of Art Beane
    Art Beane
    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
    Profile photo of Lery
    Lery
    Participant

    [quote=7931]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.[/quote]

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

You must be logged in to reply to this topic.