1

以下最小测试用例在 powershell 中引发错误:

[reflection.assembly]::LoadWithPartialName('system.xml.linq')
[system.xml.linq.xdocument]::parse('<node>&</node>')

坦率地说,在任何 .net 库中。这在存储 url 时是一个真正的问题 - 例如,如果 was 的<node>内容http://test.com/?one=a&two=b

应该如何正确编码?

4

1 回答 1

2

XML 中的编码 & 符号是&amp;

使用编码的 & 符号运行它不会引发异常:

[reflection.assembly]::LoadWithPartialName('system.xml.linq')
[system.xml.linq.xdocument]::parse('<node>&amp;</node>')
于 2012-06-23T15:33:11.847 回答