Program4Food
Member
- Joined
- Dec 6, 2021
- Messages
- 16
- Programming Experience
- 5-10
Wanting to add to XDocument to make more than one "entry" on a single write...
I think I am missing something here, not sure I understand how to do this.
I have some snippit code I massaged and got working fine, but when I add line ??? I get:
Severity Code Description Project File Line Suppression State
Error BC30452 Operator '+' is not defined for types 'XDocument' and 'XDeclaration'. vb-forms-dotnet 3.5 - xml 1 F:\VisualStudio\2015\vb-forms-dotnet 3.5 - xml 1\vb-forms-dotnet 3.5 - xml 1\Form1.vb 308 Active
I would appreciate insight on how to add another element with one write using LINQ, I had a hard enough time finding code that works just to write one element.
I think I am missing something here, not sure I understand how to do this.
I have some snippit code I massaged and got working fine, but when I add line ??? I get:
Severity Code Description Project File Line Suppression State
Error BC30452 Operator '+' is not defined for types 'XDocument' and 'XDeclaration'. vb-forms-dotnet 3.5 - xml 1 F:\VisualStudio\2015\vb-forms-dotnet 3.5 - xml 1\vb-forms-dotnet 3.5 - xml 1\Form1.vb 308 Active
I would appreciate insight on how to add another element with one write using LINQ, I had a hard enough time finding code that works just to write one element.
Line 6 is the line I added and then got the posted error.:
' used in original code, not used here Dim empNM As XNamespace = "urn:lst-emp:emp"
Dim xDoc As New XDocument(New XDeclaration("1.0", "UTF-16", Nothing), New XElement("Employees", New XElement("Employee", New XComment("Only 3 elements for demo purposes"), New XElement("EmpId", "5"), New XElement("Name", "Kimmy"), New XElement("Sex", "Female"))))
' try to add another element
xDoc = xDoc + (New XDeclaration("1.0", "UTF-16", Nothing), New XElement("Employees", New XElement("Employee", New XComment("Only 3 elements for demo purposes"), New XElement("EmpId", "5"), New XElement("Name", "Kimmy"), New XElement("Sex", "Female"))))
Dim sw As New System.IO.StringWriter()
Dim xWrite As XmlWriter = XmlWriter.Create(sw)
xDoc.Save(xWrite)
xWrite.Close()
' Save to Disk
xDoc.Save("F:\VisualStudio\DevResources\LINQxml-1.xml")
Console.WriteLine("Saved")
Last edited: