G
Guest
I have an XML file that has a date element. I want to change this date to
unix notation. This works, but if the XML does not have the element I cannot
assign the DateField the value. How can I check first if the node exists
before I try to replace it?
Public Function ConvertDates(ByVal xmldoc As XmlDocument) As XmlDocument
Dim nodelist As XmlNodeList
Dim node As XmlNode
Dim DateField As String
nodelist = xmldoc.SelectNodes("/REQUEST/IMPORT/DOCUMENT/FIELD")
For Each node In nodelist
If node.Attributes.GetNamedItem("CODE").Value = "BASE64" Then
Try
DateField = node.Item("DATETIME").InnerText()
Exit Function
Catch ex As Exception
End Try
Dim newElem As XmlNode
newElem = xmldoc.CreateNode(XmlNodeType.Element, "DATIME", "")
newElem.InnerText = xmlsvr.toUnixDateTime(DateField)
node.Item("DATETIME").InnerText = ""
node.Item("DATETIME").AppendChild(newElem)
End If
Next
Return xmldoc
End Function
unix notation. This works, but if the XML does not have the element I cannot
assign the DateField the value. How can I check first if the node exists
before I try to replace it?
Public Function ConvertDates(ByVal xmldoc As XmlDocument) As XmlDocument
Dim nodelist As XmlNodeList
Dim node As XmlNode
Dim DateField As String
nodelist = xmldoc.SelectNodes("/REQUEST/IMPORT/DOCUMENT/FIELD")
For Each node In nodelist
If node.Attributes.GetNamedItem("CODE").Value = "BASE64" Then
Try
DateField = node.Item("DATETIME").InnerText()
Exit Function
Catch ex As Exception
End Try
Dim newElem As XmlNode
newElem = xmldoc.CreateNode(XmlNodeType.Element, "DATIME", "")
newElem.InnerText = xmlsvr.toUnixDateTime(DateField)
node.Item("DATETIME").InnerText = ""
node.Item("DATETIME").AppendChild(newElem)
End If
Next
Return xmldoc
End Function