I have a Dictionary and i want to save the entries into XML.
For Each hyperlink As Xojo.Core.DictionaryEntry In mHyperlinks
Dim relationshipNode As XmlNode
relationshipNode = xml.AppendChild(XmlNode.CreateElement("Relationship"))
relationship.SetAttribute("Id", hyperlink.Value) // Value = String
Next
The code fails if there will be more then one entry. How to fix?
[code]Dim relationshipNode(-1) As XmlNode
Dim currentNode As XmlNode
For Each hyperlink As Xojo.Core.DictionaryEntry In mHyperlinks
relationshipNode.Append(xml.AppendChild(xml.CreateElement(“Relationship”)))
currentNode = relationshipNode(relationshipNode.Ubound)
currentNode.SetAttribute(“Id”, hyperlink.Value)
Next
[/code]
xml is the xmlDocument variable or is the document node of the xmlDocument variable?
ie:
dim xml as new xmlDocument
or
dim x as new xmlDocument
dim xml as xmlNode = x.appendChild(x.createElement(“MYDOC”))
Reading your code
you are in the first case, so you are trying to create a xml document with multiple root node (or document node if you prefer)
you should try:
dim xml as new xmlDocument
dim root as xmlNode =xml.appendChild(xml.createElement("mydoc"))
For Each hyperlink As Xojo.Core.DictionaryEntry In mHyperlinks
Dim relationshipNode As XmlNode
relationshipNode = root.AppendChild(XmlNode.CreateElement("Relationship")) //append your node to the root node!
relationship.SetAttribute("Id", hyperlink.Value) // Value = String
Next