将字符串解析为XML Powershell



我正试图在SharePoint Lob 中将字符串解析为XML字符串

我试图解析的字符串:

f#^)X&9uk7u%

和指定的带有转义符的字符串

f#^)X&9uk7u%

解析Powershell时抛出错误:

无法将指定的属性解析为System.String 类型

导致问题的字符是&。如果我删除&,我可以解析而不会出现任何问题。

任何想法都很棒。

代码如下

XML的属性如下

<LobSystemInstance Name="MyLobInstance" DefaultDisplayName="MyLobInstance">
<Properties>
    <Property Name="Property1" Type="System.Boolean">true</Property>
    <Property Name="Property2" Type="System.String">{Property1}</Property>
    <Property Name="Property3" Type="System.String">{Property3}</Property>
    <Property Name="Property4" Type="System.String">{Property4}</Property>
    <Property Name="Property5" Type="System.String">{Property5}</Property>
    <Property Name="Property6" Type="System.String">{Property6}</Property>
    <Property Name="Property7" Type="System.String">{Property7}</Property>
    <Property Name="Property8" Type="System.String">{Property8}</Property>
    <Property Name="Property9" Type="System.String">{Property9}</Property>
    <Property Name="Property10" Type="System.String">{Property10}</Property>
    <Property Name="Property11" Type="System.String">{Property11}</Property>
    <Property Name="Property12" Type="System.String">{Property12}</Property>
   <Property Name="Property13" Type="System.String">{Property13}</Property>
</Properties>

以下是powershell 中的命令

//-- Get the BDC Schema as a string
$bdcModelSchema = (Get-Content $bdcModelFile.FullName) | Out-String 
//Replace the strings with desired values.
$bdcModelSchema = $bdcModelSchema.Replace("{Property1}", $Property2)
$bdcModelSchema = $bdcModelSchema.Replace("{Property2}", f#^)X&9uk7u% | Out-String)
$bdcModelSchema = $bdcModelSchema.Replace("{Property3}", f#^)X&9uk7u%)
$bdcModelSchema = $bdcModelSchema.Replace("{Property4}", $Property4)
$bdcModelSchema = $bdcModelSchema.Replace("{Property5}", "Property5")
$bdcModelSchema = $bdcModelSchema.Replace("{Property6}",$Property6)
$bdcModelSchema = $bdcModelSchema.Replace("{Property7}", $Property7)
$bdcModelSchema = $bdcModelSchema.Replace("{Property8}", $Property8)
$bdcModelSchema = $bdcModelSchema.Replace("{Property9}", $Property9)
$bdcModelSchema = $bdcModelSchema.Replace("{Property10}", $Property10)
$bdcModelSchema = $bdcModelSchema.Replace("{Property11}", $Property11)
$bdcModelSchema = $bdcModelSchema.Replace("{Property12}", $Property12)
$bdcModelSchema = $bdcModelSchema.Replace("{Property13}", ($Property13))
要使r$!)X&8ul7u$成为代码中的字符串,必须将其置于单引号或双引号之间。使用双引号时,必须转义$字符。
$bdcModelSchema = $bdcModelSchema.Replace("{Property2}", 'r$!)X&8ul7u$')

$bdcModelSchema = $bdcModelSchema.Replace("{Property2}", "r`$!)X&8ul7u`$")

不起作用,因为在XML中&是元字符。

为了避免将字符串定义为

$bdcModelSchema = $bdcModelSchema.Replace("{Property2}", 'x$*)X&amp;7hl9u#')

相关内容

  • 没有找到相关文章

最新更新