无法添加前缀' xsi'

时间:2016-04-03 09:29:59

标签: xml powershell

我正在尝试向XML根节点添加属性。使用Master-PowerShell book,我可以成功地将属性添加到根节点。

但是,xsi前缀消失了。我确信这是我错过的傻事,如果能得到一些帮助我会感激不尽。以下是我的情景。

修改前的XML文件:

<?xml version="1.0" encoding="UTF-8"?>
    <InvoiceBatch>
    ...
</InvoiceBatch>

我在PowerShell中编写的代码,用于添加新属性(修改XML):

$xmldata = New-Object XML
$xmldata.Load("c:\users\SFDC_batch_0201.xml") 
$xmldata.InvoiceBatch.SetAttribute("batchSource","SFDC")
$xmldata.InvoiceBatch.SetAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")
$xmldata.InvoiceBatch.SetAttribute("xsi:noNameSpaceSchemaLocation","g:\TrgFiles\xsd\invoice.xsd")
$xmldata.Save("c:\users\SFDC_batch_0201.xml")

我得到以下输出:

<?xml version="1.0" encoding="UTF-8"?>
    <InvoiceBatch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="g:\TrgFiles\xsd\invoice.xsd" batchSource="SFDC">

    ...
    </InvoiceBatch>

输出XML(预期结果):

<?xml version="1.0" encoding="UTF-8"?>
    <InvoiceBatch batchSource="SFDC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNameSpaceSchemaLocation="g:\TrgFiles\xsd\invoice.xsd" >
    ...
    </InvoiceBatch>
很多谷歌搜索,但无法找到与我的场景相关的东西。有使用C#等,但没有使用powershell。如果我在搜索过程中遗漏了任何信息,请原谅我。

0 个答案:

没有答案
相关问题