Mike Temporale
08-30-2003, 02:11 AM
I'm having some problems saving changes to my XML documents under VB & .Net CF. This code has always worked for me before I ported it to the CF. I think the only change I made was switching SelectSingleNode to GetElementsByTagName (because the select is not recognized under CF)
I have a basic XML doc like the following:
<root>
<lists>
<list name="1" />
</lists>
</root>
and I am looking to append a child under the 'lists' element. Here's the code I'm using:
dim oDom as xmlDocument = new xmldocument
dim oDomList as xmlNode = oDom.CreateElement("list")
dim oDomListAttr as xmlAttribute = oDom.CreateAttribute("name")
oDomList.Attributes.Append(oDomListName)
oDomList.Attributes.GetNamedItem("name").value = "two"
Dim xmlMain as new xmlDocument
xmlMain.load("filename.xml")
dim newSectionnode as xmlNode = xmlMain.ImportNode(oDomList, True)
xmlMain.GetElementsByTagName("//lists").item(0).AppendChild(newSectionNode)
xmlMain.Save("filename.xml")
On the second last line (xmlMain.GetElements...) I get a system.NullReferenceException. Any help you could offer would be great.
-br
I have a basic XML doc like the following:
<root>
<lists>
<list name="1" />
</lists>
</root>
and I am looking to append a child under the 'lists' element. Here's the code I'm using:
dim oDom as xmlDocument = new xmldocument
dim oDomList as xmlNode = oDom.CreateElement("list")
dim oDomListAttr as xmlAttribute = oDom.CreateAttribute("name")
oDomList.Attributes.Append(oDomListName)
oDomList.Attributes.GetNamedItem("name").value = "two"
Dim xmlMain as new xmlDocument
xmlMain.load("filename.xml")
dim newSectionnode as xmlNode = xmlMain.ImportNode(oDomList, True)
xmlMain.GetElementsByTagName("//lists").item(0).AppendChild(newSectionNode)
xmlMain.Save("filename.xml")
On the second last line (xmlMain.GetElements...) I get a system.NullReferenceException. Any help you could offer would be great.
-br