[英]changing and xml document with powershell and then saving
所以我正在學習如何使用powershell操作xml文檔。 現在我只是想改變一個給定節點,然后保存更改。 我目前仍然堅持如何保存我的更改。
這就是我所擁有的。
$xmlfile = "testFile.xml"
$xml = [xml](get-content $xmlfile)
$employee = $xml.employees.employee
$employee[1].name = "New Name" // this is where I change the content of the xml file
//is this an okay way to change the value of the element??
$xml.save($xmlfile) //why wouldn't this line save my changes??
謝謝你的幫助 :)
您需要將完整路徑傳遞給save方法(例如$ xml.save((Resolve-Path $ xmlfile)))當您在powershell中將變量強制轉換為[xml]時,它將xml加載到XmlDocument對象中,這是的一部分。 NET Framework。 它不知道powershell,所以它不知道你的shell目前在哪個目錄。所以你上面的代碼是保存文檔,但不是在你期望的地方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.