title: Inserting both XmlDocumentType and XmlDeclaration to XmlDocument
body: <p>I have some trouble creating my XmlDocument class. This is what I've tried to do:</p>
  
  <pre><code>Dim myDoc = New XmlDocument()
  
  Dim docType As XmlDocumentType = myDoc.CreateDocumentType("DtdAttribute", Nothing, "DtdFile.dtd", Nothing)
  myDoc.XmlResolver = Nothing
  myDoc.AppendChild(docType)
  
  Dim xmldecl As XmlDeclaration = myDoc.CreateXmlDeclaration("1.0", Encoding.GetEncoding("ISO-8859-15").BodyName, "yes")
  
  Dim root As XmlElement = myDoc.CreateElement("RootElement")
  
  myDoc.AppendChild(root)
  myDoc.InsertBefore(xmldecl, root)
  </code></pre>
  
  <p>This will result in error: Cannot insert the node in the specified location. Line throwing this error is <code>myDoc.InsertBefore(xmldecl, root)</code></p>
  
  <p>Just cannot figure out this. Which order should I insert these elements? I've tried different orders but I think I'm just doing something totally wrong and this shouldn't even work in the first place :) But then how to do this?</p>