fork(3) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using System.Xml;
  6. namespace ConsoleApplication1
  7. {
  8. class Program
  9. {
  10. public static void Main(string[] args)
  11. {
  12. var doc = new XmlDocument();
  13. var stream = new MemoryStream();
  14.  
  15. XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "utf-8", null);
  16. XmlElement rootNode = doc.CreateElement("rexim");
  17. rootNode.InnerText = "давлоыдаывалдыовадлы";
  18. rootNode.SetAttribute("xmlns", "rexim:coding-team:test");
  19. doc.InsertBefore(xmlDeclaration, doc.DocumentElement);
  20. doc.AppendChild(rootNode);
  21.  
  22. XmlWriterSettings settings = new XmlWriterSettings()
  23. {
  24. Indent = true
  25. };
  26.  
  27. using( var writer = XmlWriter.Create(stream,settings)) {
  28. doc.Save(writer);
  29. }
  30. }
  31. }
  32. }
  33.  
Runtime error #stdin #stdout #stderr 0.08s 30736KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Unhandled Exception:
System.Xml.XmlException: Cannot redefine the namespace for prefix '' used at current element
  at System.Xml.XmlTextWriter.WriteEndAttribute () [0x00000] in <filename unknown>:0 
  at System.Xml.DefaultXmlWriter.WriteEndAttribute () [0x00000] in <filename unknown>:0 
  at System.Xml.XmlAttribute.WriteTo (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlElement.WriteTo (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.WriteContentTo (System.Xml.XmlWriter xw) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.Save (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
  at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Xml.XmlException: Cannot redefine the namespace for prefix '' used at current element
  at System.Xml.XmlTextWriter.WriteEndAttribute () [0x00000] in <filename unknown>:0 
  at System.Xml.DefaultXmlWriter.WriteEndAttribute () [0x00000] in <filename unknown>:0 
  at System.Xml.XmlAttribute.WriteTo (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlElement.WriteTo (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.WriteContentTo (System.Xml.XmlWriter xw) [0x00000] in <filename unknown>:0 
  at System.Xml.XmlDocument.Save (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
  at ConsoleApplication1.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0