2010-11-30 50 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()