我曾经有一个填充变量的XML文件([xml]$modificationData = Get-Content $modificationXmlFileName)但现在我无法存储文件,必须把它放到一个不同的数据文件中,我告诉的格式是这样做是:
xmldata = @' <bigSection> <smallSection> <changes> </changes> </smallSection> </bigSection> '@我不确定Get-Content cmdlet现在是否可以正常工作,如果我将它连接到这个新变量并且我不完全确定我还能使用什么。
另外,我不知道@''@包围代码意味着什么。 我认为@符号用于数组,但我不认为它在这种情况下会这样做。
任何澄清都会有所帮助。
I used to have an XML file that was populating a variable ([xml]$modificationData = Get-Content $modificationXmlFileName) but now I am unable to store the file and must put it into a a different datafile, the format that I was told to do this in is:
xmldata = @' <bigSection> <smallSection> <changes> </changes> </smallSection> </bigSection> '@I'm not sure if the Get-Content cmdlet would work now if I rout it to this new variable and I'm not entirely sure what else I could use.
Also, I don't know what the @''@ wrapping around the code means. I thought the @ symbol was used for arrays but I dont think that it does that in this case.
Any clarification would be helpful.
最满意答案
@'...'@语法称为here字符串或here文档。 这是一种指定字符串而不必转义字符的方法。
Get-Content用于读取文件。 当你默认调用它时,它会返回一个行数组,除非你用-Raw参数调用它(然后它将返回一个包含文件所有内容的大字符串)。
因此,在您的示例中, $xmldata与调用Get-Content $modificationXmlFileName -Raw 。
因为你只是想要转换为[xml] ,你可以这样做:
$xmldata = [xml]@' ... '@The @'...'@ syntax is called a here string or a here document. It's a way of specifying a string without having to escape characters.
Get-Content is for reading files. When you call it by default, it returns an array of lines, unless you call it with the -Raw parameter (and then it would return one big string with all the content of the file).
So in your example, $xmldata is the same as if you had called Get-Content $modificationXmlFileName -Raw.
Since you're just trying to cast to [xml], you can just do that:
$xmldata = [xml]@' ... '@更多推荐
发布评论