EDN Admin
Well-known member
I am very new to XMLDocument. I have the following code which works when my XML file was not found and therefore has just been created. But it fails when the XML file was found.
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim NewPersDataNode <span style="color:Blue; As XmlElement
NewPersDataNode = xmlDoc.CreateElement(<span style="color:#A31515; "PersonalDataMemory")
NewPersDataNode.SetAttribute(<span style="color:#A31515; "Updated", DateTime.Now.ToString)
<span style="color:Blue; For <span style="color:Blue; Each persinf <span style="color:Blue; As PersonalInfo <span style="color:Blue; In PersonalData
<span style="color:Blue; Dim Element <span style="color:Blue; As XmlElement = xmlDoc.CreateElement(persinf.URLXMLtext)
<span style="color:Blue; Dim Text <span style="color:Blue; As XmlText = xmlDoc.CreateTextNode(persinf.value)
NewPersDataNode.AppendChild(Element)
Element.AppendChild(Text)
<span style="color:Blue; Next
rootNode.ReplaceChild(NewPersDataNode, PersDataNode) <span style="color:Green; << it fails here because PersDataNode is Nothing
[/code]
<br/>
The code that creates the file is ...
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; Create the root element
rootNode = xmlDoc.CreateElement(<span style="color:#A31515; "AllMemory")
xmlDoc.InsertBefore(xmlDecl, xmlDoc.DocumentElement)
xmlDoc.AppendChild(rootNode)
<span style="color:Green; Create elements subordinate to root and add them to the root node
AppMemoryNode = xmlDoc.CreateElement(<span style="color:#A31515; "AppMemory")
AppMemoryNode.SetAttribute(<span style="color:#A31515; "Updated", DateTime.Now.ToString)
xmlDoc.DocumentElement.AppendChild(AppMemoryNode)
PersDataNode = xmlDoc.CreateElement(<span style="color:#A31515; "PersonalDataMemory")
PersDataNode.SetAttribute(<span style="color:#A31515; "Updated", DateTime.Now.ToString)
xmlDoc.DocumentElement.AppendChild(PersDataNode)
[/code]
I think I understand what is going on - since the file existed I havent been through the code which assigns any value to PersDataNode. But I dont see any way to assign the correct value to PersDataNode for the existing XML. I think that I need
a SelectElementByPath but I see no method which sounds like that.
How do I get my PersDataNode element connected to the right part of my existing file?
BTW, what the difference between a Node and an Element? They sure look very similar to me.
Thanks, Bob
View the full article
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim NewPersDataNode <span style="color:Blue; As XmlElement
NewPersDataNode = xmlDoc.CreateElement(<span style="color:#A31515; "PersonalDataMemory")
NewPersDataNode.SetAttribute(<span style="color:#A31515; "Updated", DateTime.Now.ToString)
<span style="color:Blue; For <span style="color:Blue; Each persinf <span style="color:Blue; As PersonalInfo <span style="color:Blue; In PersonalData
<span style="color:Blue; Dim Element <span style="color:Blue; As XmlElement = xmlDoc.CreateElement(persinf.URLXMLtext)
<span style="color:Blue; Dim Text <span style="color:Blue; As XmlText = xmlDoc.CreateTextNode(persinf.value)
NewPersDataNode.AppendChild(Element)
Element.AppendChild(Text)
<span style="color:Blue; Next
rootNode.ReplaceChild(NewPersDataNode, PersDataNode) <span style="color:Green; << it fails here because PersDataNode is Nothing
[/code]
<br/>
The code that creates the file is ...
<div style="color:Black;background-color:White; <pre>
<span style="color:Green; Create the root element
rootNode = xmlDoc.CreateElement(<span style="color:#A31515; "AllMemory")
xmlDoc.InsertBefore(xmlDecl, xmlDoc.DocumentElement)
xmlDoc.AppendChild(rootNode)
<span style="color:Green; Create elements subordinate to root and add them to the root node
AppMemoryNode = xmlDoc.CreateElement(<span style="color:#A31515; "AppMemory")
AppMemoryNode.SetAttribute(<span style="color:#A31515; "Updated", DateTime.Now.ToString)
xmlDoc.DocumentElement.AppendChild(AppMemoryNode)
PersDataNode = xmlDoc.CreateElement(<span style="color:#A31515; "PersonalDataMemory")
PersDataNode.SetAttribute(<span style="color:#A31515; "Updated", DateTime.Now.ToString)
xmlDoc.DocumentElement.AppendChild(PersDataNode)
[/code]
I think I understand what is going on - since the file existed I havent been through the code which assigns any value to PersDataNode. But I dont see any way to assign the correct value to PersDataNode for the existing XML. I think that I need
a SelectElementByPath but I see no method which sounds like that.
How do I get my PersDataNode element connected to the right part of my existing file?
BTW, what the difference between a Node and an Element? They sure look very similar to me.
Thanks, Bob
View the full article