xmlwriter writedoctype格式化

时间:2010-11-30 01:20:50

标签: .net xml powershell doctype

我正在尝试生成此doctype字符串:

<!DOCTYPE games SYSTEM "transform.dtd">

这就是我一直在尝试的:

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

我不完全确定如何获得确切的行。

1 个答案:

答案 0 :(得分:6)

PowerShell中存在一个已知错误: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()