Results 1 to 2 of 2

Thread: Date from XML

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2010
    Posts
    42

    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

  2. #2
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    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
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width