writeelementstring

C#: XmlTextWriter.WriteElementString fails on empty strings?

冷暖自知 提交于 2019-11-28 00:02:45
I'm using XmlTextWriter and its WriteElementString method, for example: XmlTextWriter writer = new XmlTextWriter("filename.xml", null); writer.WriteStartElement("User"); writer.WriteElementString("Username", inputUserName); writer.WriteElementString("Email", inputEmail); writer.WriteEndElement(); writer.Close(); The expected XML output is: <User> <Username>value</Username> <Email>value</Email> </User> However, if for example inputEmail is empty, the result XML I get as as follows: <User> <Username>value</Username> <Email/> </User> Whereas I would expect it to be: <User> <Username>value<

C#: XmlTextWriter.WriteElementString fails on empty strings?

最后都变了- 提交于 2019-11-26 21:39:46
问题 I'm using XmlTextWriter and its WriteElementString method, for example: XmlTextWriter writer = new XmlTextWriter("filename.xml", null); writer.WriteStartElement("User"); writer.WriteElementString("Username", inputUserName); writer.WriteElementString("Email", inputEmail); writer.WriteEndElement(); writer.Close(); The expected XML output is: <User> <Username>value</Username> <Email>value</Email> </User> However, if for example inputEmail is empty, the result XML I get as as follows: <User>