4
我有以下存根XML文件PowerShell的XML属性命名空间
<ResourceDictionary x:Uid="CultureResources"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<system:String x:Uid="system::.CultureName" x:Key=".CultureName">de-DE</system:String>
</ResourceDictionary>
我绑自动生成它在它目前正与下面的测试代码
[xml]$xmlfile = Get-Content "c:\test.xml"
[System.Xml.XmlNamespaceManager] $nsm = new-object System.Xml.XmlNamespaceManager $xmlfile.NameTable
$nsm.AddNamespace("x", "http://schemas.microsoft.com/winfx/2006/xaml")
$nsm.AddNamespace("system", "clr-namespace:System;assembly=mscorlib")
$nn = $xmlfile.CreateElement("system:String", $nsm)
$nn.set_InnerText("de-DE")
$nn.SetAttribute("Uid","system:.CultureName")
$nn.SetAttribute("Key",".CultureName")
$xmlfile.ResourceDictionary.AppendChild($nn)
但显示相同的方式输出我得到的是
<ResourceDictionary x:Uid="CultureResources"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<system:String x:Uid="system::.CultureName" x:Key=".CultureName">de-DE</system:String>
<system:String Uid="system:.CultureName" Key=".CultureName" xmlns:system=" xmlns xml x system">de-DE</system:String>
</ResourceDictionary>
我如何:
A)摆脱了命名空间文本
xmlns:system=" xmlns xml x system"
B)的前缀属性我用 “X:”
任何帮助,将不胜感激。
问候,
瑞安
优秀的感谢,我只是拿出我自己的代码,并没有公布这几乎是为你所做的只是一些额外的相同因为我不知道你使用过的一些简短表格。 另一个令人困惑的地方是“xmlns:system =”xmlns xml x system“”出现,但这是由于我在查看“outertext”字段并假设它是实际输出。 – Ryan
外部xml等于acutal输出。你得到xmlns部分的原因是你使用了过载错误。你给namespaceuri-paramter'$ nms'作为值,而不是uri本身。 '$ nms'是一个管理器,所以当你使用它作为输入时,你得到它的名字空间(xmlns,xml,x,system)作为命名空间uri。 –