2017-10-05 88 views
0

我想在PowerShell中使用xmlstarlet,在C#應用程序中啓動Process。 我的主要問題是,當我使用此代碼:Xmlstarlet編碼和PowerShell裏面的進程C#

./xml.exe ed -N ns=http://www.w3.org/2006/04/ttaf1 -d '//ns:div[not(contains(@xml:lang,''Italian''))]' "C:\Users\1H144708H\Downloads\a.mul.ttml" > "C:\Users\1H144708H\Downloads\a.mul.ttml.conv" 

在PowerShell中,我得到了錯誤的編碼(我需要UTF-8)的文件。

巴蜀我以前只是

export LANG=it_IT.UTF-8 && 

xmlstarlet之前,但在PowerShell中我真的不知道該怎麼做。 也許有另一種方法,我看到xmlstarlet能夠使用sel --encoding utf-8,但我不知道如何在ed模式下使用它(我嘗試在ed之後的xml.exe之後使用它。但它總是失敗)。

什麼是導出LANG = it_IT.UTF-8或如何使用 - 編碼UTF-8的替代方案?

PS。我試過很多,很多事情,如:

$MyFile = Get-Content "C:\Users\1H144708H\Downloads\a.mul.ttml"; $Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False; [System.IO.File]::WriteAllLines("C:\Users\1H144708H\Downloads\a.mul.ttml.conv", $MyFile, $Utf8NoBomEncoding) 

和:

./xml.exe ed -N ns=http://www.w3.org/2006/04/ttaf1 -d '//ns:div[not(contains(@xml:lang,''Italian''))]' "C:\Users\1H144708H\Downloads\a.mul.ttml" | Out-File "C:\Users\1H144708H\Downloads\a.mul.ttml.conv" -Encoding utf8 

但類似E I U字仍然是錯誤的。如果我在轉換之前嘗試使用記事本保存原始文件(僅當我不使用xmlstarlet時)...但我需要在PowerShell中執行同樣的操作,但我不知道如何執行。

編輯。 我能打印在PowerShell中我UTF8:

Get-Content -Path "C:\Users\1H144708H\Downloads\a.mul.ttml" -Encoding UTF8 

但我還是沒能做到同樣的事情xmlstarlet。

回答

0

最後我決定創建一個本地C#方法,並且我只是使用一個StreamReader來ReadLine通過行文件。用一個簡單的包含我決定xml:lang =「語言」在哪裏,然後我開始將每一行添加到一個字符串。當然,我在while循環之前添加了文件的頭部和尾部,並且當我讀取包含的一行時,我停止添加每一行。我知道這不是做事情的最佳方式,但它適用於我的情況。