我正在使用Powershell的Microsoft服务器。 我要做的任务是获取并设置"测试用例"类型的给定工作项的"步骤"。
,TFS在XML文档中存储诸如 HTML HTML这样的信息,以避免HTML元素,从而避免使用 XML 。
下面是一个示例:
复制代码
I do this and that
I do something else
This happens
显示为:
如何获得每个项目的"纯文本"? 比如 This happens 离开了
This happens
html
powershell
tfs
时间:17年09月18日原作者:jir 共1个回答
0 0
在 System.Web 命名空间中有一些可以帮助你的东西:
复制代码PS> add-type -AssemblyName system.web
PS> [System.Web.HttpUtility]::HtmlDecode("Baskin & Robbins")Baskin & Robbins
更新
我又读了你的问题,你想要的不止这个。 如果你不熟悉xml和html语义,那么这是一个有点复杂的问题,因这里这是一个脚本。 我希望你能根据需要修改它。
复制代码add-type -AssemblyName system.web
$raw = @'
I do this and that
I do something else
This happens
'@$xml = [xml]$raw
$xml.steps.step | foreach-object {
write-host ('Processing {0}...' -f $_.type)
$_.parameterizedString | foreach-object {
# decode html entities
$html = [System.Web.HttpUtility]::HtmlDecode($_.innerText)
# let's hope the html is balanced and valid xhtml (matching begin/end tags)
# assumption is that the innermost
wraps the desired text
# match with xpath
$text = ([xml]$html).SelectSingleNode('//P/text()').value
write-host"Text: '$text'"
}}