2010-11-30 48 views
2

我試圖生成此文檔類型的字符串:的XmlWriter writedoctype格式化

<!DOCTYPE games SYSTEM "transform.dtd"> 

這是我一直想:

$writer.WriteDocType("games", $null , "transform.dtd", $null) 

我不完全知道如何獲取準確線。

回答

6

有PowerShell中的一個已知的bug:passing null to a string parameter results in a String.Empty instead of null.

你可以解決它是這樣的:

# Given an XML writer of some sort ... 
$writer = [system.xml.xmlwriter]::create("$pwd\test.xml") 

# Set up the parameters you want to pass to the method: 
$params = @("games",$null,"transform.dtd",$null) 

# And invoke it using .Net reflection: 
$writer.GetType().GetMethod("WriteDocType").Invoke($writer,$params) 

# Eventually, close the writer: 
$writer.Close()