I am trying to achieve the following code in one line without declaring a variable. The code will create an XML element, add an attribute and a value and finally append it to the XML document:
Dim XMLDoc As New XmlDocument
Dim XMLRoot As XmlElement
XMLRoot = XMLDoc.CreateElement("Test1")
XMLRoot.Attributes.Append(XMLDoc.CreateAttribute("Test2")).Value = "Test3"
XMLDoc.AppendChild(XMLRoot)
I have tried the following but it returns an error: Boolean cannot be converted to 'XmlNode'.
Dim XMLDoc As New XmlDocument
XMLDoc.AppendChild(XMLDoc.CreateElement("Test1").Attributes.Append(XMLDoc.CreateAttribute("Test2").Value = "Test3"))
This returns error: Expression does not produce a value.
Dim XMLDoc As New XmlDocument
XMLDoc.AppendChild(XMLDoc.CreateElement("Test1").SetAttribute("Test2", "Test3"))
.AppendChildmethod expects a value of typeXmlElement. If element creation is complicated, wrap it with the method which returns created element and pass it to the.AppendChild()