Process C#中的Xmlstarlet ed编码和Powershell [英] Xmlstarlet ed encoding and powershell inside Process C#

查看:94
本文介绍了Process C#中的Xmlstarlet ed编码和Powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从C#应用程序中以Process开头的Powershell中使用xmlstarlet。
我的主要问题是当我使用此代码时:

I want to use xmlstarlet from the powershell started with Process in a C# application. My main problem is that when I use this code:

./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)。

on powershell I get a file with the wrong encoding (I need UTF-8).

在Bash上,我以前只是

On Bash I used to just

export LANG=it_IT.UTF-8 && 

在xmlstarlet之前,但是在powershell上,我真的不知道该怎么做。
也许还有一种选择,我看到xmlstarlet能够使用sel --encoding utf-8,但是我不知道如何在ed模式下使用它(我试图在ed之后的xml.exe之后使用它等等...但是它总是失败)。

before xmlstarlet but on powershell I really don't know how to do it. Maybe there is an alternative, I saw that xmlstarlet is able to use sel --encoding utf-8 but I don't know how to use it in ed mode (I tried to use it after xml.exe after ed etc... but it always fail).

导出LANG = it_IT.UTF-8的替代方法是什么?如何使用--encoding utf-8?

What is the alternative to export LANG=it_IT.UTF-8 or how to use --encoding utf-8?

PS。我尝试了很多类似的事情:

PS. I tried many and many things like:

$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

但是像èàù这样的字符仍然是错误的。如果我尝试在转换之前使用记事本保存原始文件,则该文件可以工作(仅当我不使用xmlstarlet时)...但是我需要在powershell中执行相同的操作,而我不知道如何。

But characters like è à ì ù are still wrong. If I try to save the original file with Notepad before the conversion it works (only if I don't use xmlstarlet)... but I need to do the same thing in powershell and I don't know how.

编辑。
我能够在Powershell上打印utf8:

EDIT. I was able to print my utf8 on powershell:

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

但我仍然

推荐答案

最后,我决定创建一个本机C#方法,我只是使用了将StreamReader逐行读取到ReadLine。通过一个简单的包含,我确定xml:lang = Language在哪里,然后开始将每行添加到字符串中。当然,我在while循环之前添加了文件的开头和结尾,并且在读取包含的行时停止添加每一行。我知道这不是做事情的最佳方法,但它适用于我的情况。

In the end I decided to create a native C# method and I just used a StreamReader to ReadLine by line the file. With a simple Contains I decide where is the xml:lang="Language" and I then start to add every line to a string. Of course I added the head and the end of my file before the while loop and I stop to add every line when I read a line that Contains . I know that this is not the best way to do things, but it works for my case.

这篇关于Process C#中的Xmlstarlet ed编码和Powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆