how to give id to tag in xml

how to give id to a tag in xml using script

XmlElement elmNew1 = xmlDoc.CreateElement("con1");
XmlElement X1 = xmlDoc.CreateElement("aaa");
X1.InnerText = ("hhh");
elmNew1.AppendChild(X1); 

for con 1 i have to give id = 1.

How can i give??

You need to create an attribut and set that on the element. See this: XmlDocument.CreateAttribute Method (System.Xml) | Microsoft Learn

Basically

    var id = xmlDoc.CreateAttribute("id");
    id.Value = 1;
    X1.SetAttributeNode(id);