-
Date from XML
I'm working on a countdown program for a client of mine.
He wants to be able to edit the end date in an xml file, accurate to the second.
I got the timer working fine atm, but i'm kinda struggling with the xml file.
Any of you guys have tips on how i should setup the xml file? and most importantly, how do i extract that same date within the xml file, for use in my program?
Thanks,
Mark
-
Re: Date from XML
Here's an example I just to build some XML:
Code:
Public Shared Function BuildBookInMemory(strRoot As String, strHeader As String, Data As OleDbDataReader) As XmlDocument
'Create this:
' <?xml version="1.0"?>
' <Library>
' <Book BookType="ExistsInDB">
' <ID>1</ID>
' <Author>Joe</Author>
' <AuthorID>1</AuthorID>
' <Comment>Excellent</Comment>
' <CommentID>1</CommentID>
' <Read>False</Read>
' <Title>book 1</Title>
' </Book>
' </Library>
'
Dim r As Integer
Dim xmlBook As XmlDocument
Dim xmlDec As XmlDeclaration
Dim xmlRoot As XmlElement
Dim xmlFirstNode As XmlElement
Dim xmlNode As XmlElement
Dim strNodes As String() = {"ID", "AuthorID", "Author", "CommentID", "Comment", "Read", _
"Title"}
xmlBook = New XmlDocument()
xmlDec = xmlBook.CreateXmlDeclaration("1.0", Nothing, Nothing)
xmlBook.AppendChild(xmlDec)
xmlRoot = xmlBook.CreateElement(strRoot)
xmlBook.AppendChild(xmlRoot)
xmlFirstNode = xmlBook.CreateElement(strHeader)
xmlFirstNode.SetAttribute("BookType", "ExistsInDB")
xmlRoot.AppendChild(xmlFirstNode)
For r = 0 To 6
xmlNode = xmlBook.CreateElement(strNodes(r))
xmlNode.InnerText = Data(r).ToString()
xmlFirstNode.AppendChild(xmlNode)
Next
Return xmlBook
End Function
Public Shared Function BuildBookForDB(strRoot As String, strHeader As String, Book As Books.Book) As XmlDocument
Dim r As Integer
Dim xmlBook As XmlDocument
Dim xmlDec As XmlDeclaration
Dim xmlRoot As XmlElement
Dim xmlFirstNode As XmlElement
Dim xmlNode As XmlElement
Dim strNodes As String() = {"ID", "AuthorID", "CommentID", "Read", "Title"}
xmlBook = New XmlDocument()
xmlDec = xmlBook.CreateXmlDeclaration("1.0", Nothing, Nothing)
xmlBook.AppendChild(xmlDec)
xmlRoot = xmlBook.CreateElement(strRoot)
xmlBook.AppendChild(xmlRoot)
xmlFirstNode = xmlBook.CreateElement(strHeader)
xmlFirstNode.SetAttribute("BookType", "ExistsInDB")
xmlRoot.AppendChild(xmlFirstNode)
For r = 0 To 3
xmlNode = xmlBook.CreateElement(strNodes(r))
Select Case r
Case 0
xmlNode.InnerText = Book.ID.ToString()
Exit Select
Case 1
xmlNode.InnerText = Book.AuthorID.ToString()
Exit Select
Case 2
xmlNode.InnerText = Book.CommentID.ToString()
Exit Select
Case 3
xmlNode.InnerText = Book.Read.ToString()
Exit Select
Case 4
xmlNode.InnerText = Book.Title
Exit Select
End Select
xmlFirstNode.AppendChild(xmlNode)
Next
Return xmlBook
End Function