Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell: Convert XML to String

I am searching for a way to convert a XML-Object to string.

Is there a way like $xml.toString() in Powershell?

like image 821
uprix Avatar asked Mar 14 '13 13:03

uprix


People also ask

How do I convert XML to PowerShell?

Casting XML Strings to Objects Another way to use PowerShell to parse XML is to convert that XML to objects. The easiest way to do this is with the [xml] type accelerator. By prefixing the variable names with [xml] , PowerShell converts the original plain text XML into objects you can then work with.

Can PowerShell read XML?

PowerShell and Reading XML filesPowerShell provides an easy way to read XML files, manipulate them and finally to save them back to disk without writing a lot of code or knowing XPath. PowerShell does this by providing the user dot notation to signify each node in the XML document.

How do I convert XML to CSV in PowerShell?

Use ConvertTo-Csv to Convert XML to CSV in PowerShell You can use the Set-Content cmdlet to write CSV strings to a file. The Set-Content is a string-processing cmdlet that writes new content or replaces the content in a file. The content objects are sent down the pipeline to the ConvertTo-Csv cmdlet.


2 Answers

You are probably looking for OuterXml.

$xml.OuterXml should give you what you want.

like image 110
Stanley De Boer Avatar answered Sep 17 '22 13:09

Stanley De Boer


How are you creating the XML object?

Typically, if you want an XML string from an object, you'd use:

$object | ConvertTo-Xml -As String 
like image 45
mjolinor Avatar answered Sep 21 '22 13:09

mjolinor