XML xsi:type属性仅显示类型

时间:2018-10-09 10:18:42

标签: xml powershell xsitype

我需要配置XML名称空间来实现此目的,但是我发现的所有代码都是人们想要读取使用哪个名称空间而不是配置名称空间的人。 假设我将命名空间添加为这样的属性

[xml]$batch = New-Object System.Xml.XmlDocument
$batch.AppendChild($batch.CreateXmlDeclaration("1.0", "UTF-8", $null))
$req = $batch.CreateNode("element", "batchRequest", $null)
#$req.SetAttribute("xmlns:xsd", "http://www.w3c.org/2001/XMLSchema")
#$req.SetAttribute("xmlns:xsi", "http://www.w3c.org/2001/XMLSchema-instance")

稍后,我添加一个使用此属性的 child

$entvalue = $batch.CreateElement("value")
$entvalue.InnerText = $base64entitlement #adds a base64 string as value
#set attributes using previously defined namespaces
$entvalue.SetAttribute('xsi:type', 'xsd:base64Binary')
$entitlementrefattr.AppendChild($entvalue)
$rolerequest.AppendChild($entitlementrefattr)
#Append Role to Batchrequest
$req.AppendChild($rolerequest)

请注意,无法更改XML的写入方式,它已被现有的软件所使用,因此希望XML以某种方式被写入。

$entvalue的预期输出为:

<value xsi:type="xsd:base64Binary">(base64string)</value>

但是我明白了

<value type="xsd:base64Binary">(base64string)</value>

很显然,我需要以另一种方式定义名称空间,但似乎无法弄清楚该怎么做。

0 个答案:

没有答案
相关问题