While lines 5 and 6 create elements, they aren't automatically added to the xmldoc. From the documentation "Although this method creates the new object in the context of the document, it does not automatically add the new object to the document tree. To add the new object, you must explicitly call one of the node insert methods."

While lines 5 and 6 create elements, they aren't automatically added to the xmldoc. From the documentation "Although this method creates the new object in the context of the document, it does not automatically add the new object to the document tree. To add the new object, you must explicitly call one of the node insert methods."

Your line 3 creates an xmldocument, that's all good. Lines 5,6 create xmlelements but, even though you use the xmldocument that you created to create these, they are not a part of the xmldocument that you created. You need to add them to the xmldocument using one of the xmldocument insert methods. For example, AppendChild() should work: