I'm looking for a way to get xml content in string or in html:
I have an xml like:
<xml>
<Students>
<Name>Karan</Name>
<Name>Rohan</Name>
<Name>Jack</Name>
<Name>Roy</Name>
</Students>
</xml>
I wrote following code:
[xml]$Xml = Get-Content (student.xml)
$str = ConvertTo-Xml -InputObject $Xml.InnerXml -As Stream
But, it gives following string to $str and that too in a single line:
<?xml version="1.0"?> <Objects> <Object Type="System.String"><Class><Students><Name>Karan</Name><Name>Rohan</Name><Name>Jack</Name><Name>Roy</Name></Students&g
t;</Class></Object> </Objects>
But I want the string in following format including the whitespaces:
'<xml>
<Students>
<Name>Karan</Name>
<Name>Rohan</Name>
<Name>Jack</Name>
<Name>Roy</Name>
</Students>
</xml>'
也许
$str=gc C:\temp\test.xml |Out-String
这样可以在保留格式的同时为您提供XML数据。
[String]$str = Get-Content -Path "student.xml" -Raw
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.