を使用して実行時に構築される次の XML がありますXmlDocument
。
<?xml version="1.0" standalone="yes"?>
<NewConfig xmlns="http://tempuri.org/NewConfig.xsd">
<SystemReference xmlns="">
<ID>1</ID>
<Name>CountryName</Name>
</SystemReference>
<ClientList xmlns="">
<Type>Private</Type>
<!-- elements omitted... -->
<VAT>1234567890</VAT>
</ClientList>
</NewConfig>
次のコードを使用して、この XML を TCP ソケットに保存しています。
TcpClient client = ...
XmlDocument configDocument = ...
using (StreamWriter writer = new StreamWriter(client.GetStream()))
{
writer.AutoFlush = true;
configDocument.Save(writer);
writer.WriteLine();
}
ただし、これにより、ソケットの反対側で受信される XML が切り捨てられます。最後の 2 つの要素 (</ClientList>
と</NewConfig>
) は存在しません。
ただし、次のコードを使用すると、XML は正常に送信されます。
TcpClient client = ...
XmlDocument configDocument = ...
using (StreamWriter writer = new StreamWriter(client.GetStream()))
{
writer.AutoFlush = true;
writer.WriteLine(configDocument.OuterXml);
}
XmlDocument.Save()
したがって、私の質問は次のとおりです。への書き込み時に終了要素を無視しているように見える理由を誰かが知っていStream
ますか?