Как я могу расположить Систему. Xml. XmlWriter в PowerShell

Вы можете использовать регулярные выражения здесь:

import re
result = re.findall(r'(.*?)<', html_document)

10
задан alex2k8 14 April 2009 в 00:57
поделиться

2 ответа

Утилизация защищена в System.Xml.XmlWriter . Вместо этого вы должны использовать Close .

$writer.Close
11
ответ дан 3 December 2019 в 20:06
поделиться

Here is an alternative approach:

(get-interface $obj ([IDisposable])).Dispose()

Get-Interface script can be found here http://www.nivot.org/2009/03/28/PowerShell20CTP3ModulesInPracticeClosures.aspx and was suggested in this response.

With 'using' keyword we get:

$MY_DIR = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent

# http://www.nivot.org/2009/03/28/PowerShell20CTP3ModulesInPracticeClosures.aspx
. ($MY_DIR + '\get-interface.ps1')

# A bit modified code from http://blogs.msdn.com/powershell/archive/2009/03/12/reserving-keywords.aspx
function using
{
    param($obj, [scriptblock]$sb)

    try {
        & $sb
    } finally {
        if ($obj -is [IDisposable]) {
            (get-interface $obj ([IDisposable])).Dispose()
        }
    }
}

# Demo
using($writer = [System.Xml.XmlWriter]::Create('c:\some.xml')) {

}
8
ответ дан 3 December 2019 в 20:06
поделиться
Другие вопросы по тегам:

Похожие вопросы: