Results 1 to 8 of 8

Thread: quick xml write question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    quick xml write question

    Hi all,

    I was around here a while back and received some excellent help and advice and was hoping for a bit more, what it is I am trying to write an xml file in VB.

    I need to get the xml file like this
    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <images>
    <photo>
    <image>my_images\1.jpg</image>
    </photo>
    <photo>
    <image>my_images\logos.jpg</image>
    </photo>
    </images>

    but I can only get it like this

    <?xml version="1.0"?>
    <images>
    <pic>
    <song path="C:\Program Files\mgamerz\my_images\ 116941_4039.jpg" artist="" title="116941_4039.jpg"/>
    <song path="C:\Program Files\mgamerz\my_images\ logos2.jpg" artist="" title="logos2.jpg"/>
    <song path="C:\Program Files\mgamerz\my_images\ victorian_christmas2a.jpg" artist="" title="victorian_christmas2a.jpg"/>
    </pic>
    </images>

    the reason why the naming is different is because I am using an old app I made for adding mp3 files and was just wondering what I need to change to acheive the xml formatting.

    heres my code if it helps

    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3.  
    4.     Dim f1 As Integer, jpgurl As String, MyPath As String, Artist As String, xmlpath As String, songpath As String, slidenode As String, songname As String, mp3path As String, f2 As Integer, i As Integer
    5.    
    6.    
    7.     mp3path = "C:\Program Files\mgamerz\my_images\"
    8.    
    9.      f2 = FreeFile
    10.     Open mp3path & "mp3.txt" For Output As #f2       ' if you don't need mp3.txt take out
    11.      f1 = FreeFile
    12.      
    13.     Open mp3path & "slides.xml" For Output As #f1
    14.     Print #f1, "<?xml version=""1.0""?>"
    15.     Print #f1, "<images>"
    16.     Print #f1, "<pic>"
    17.     songname = Dir(mp3path & "\*.jpg")   ' get first track
    18.     i = 1
    19.     While Not Len(songname) = 0
    20.         MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath) + 1)) & " " & songname
    21.        
    22.        songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & songname & """/> "
    23.         Print #f1, songpath
    24.         Print #f2, songname                  ' for mp3.txt
    25.         Sleep 100                                ' slight pause, needed
    26.         songname = Dir                         ' get next track
    27.    
    28.     Wend
    29.     Print #f1, "</pic>"
    30.     Print #f1, "</images>"
    31.  
    32.  
    33. Close
    34. End Sub

    hope someon can shed some light

    thanks in advance
    R

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: quick xml write question

    Move the printing of the Photo and Image tags into the While loop.

    VB Code:
    1. Private Sub Command2_Click()
    2.     Dim f1 As Integer, jpgurl As String, MyPath As String, Artist As String, xmlpath As String, songpath As String, slidenode As String, songname As String, mp3path As String, f2 As Integer, i As Integer
    3.    
    4.    
    5.     mp3path = "C:\Program Files\mgamerz\my_images\"
    6.    
    7.      f2 = FreeFile
    8.     Open mp3path & "mp3.txt" For Output As #f2       ' if you don't need mp3.txt take out
    9.      f1 = FreeFile
    10.      
    11.     Open mp3path & "slides.xml" For Output As #f1
    12.     Print #f1, "<?xml version=""1.0""?>"
    13.     Print #f1, "<images>"
    14.     songname = Dir(mp3path & "\*.jpg")   ' get first track
    15.     i = 1
    16.     While Not Len(songname) = 0
    17.         Print #f1, "<photo>"
    18.         Print #f1, "<image>"
    19.  
    20.          Print #f1, mp3path & songname
    21.         Sleep 100                                ' slight pause, needed
    22.         songname = Dir                         ' get next track
    23.  
    24.  
    25.         Print #f1, "</image>"
    26.         Print #f1, "</photo>"
    27.    
    28.     Wend
    29.     Print #f1, "</images>"
    30.  
    31. Close
    32. End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: quick xml write question

    great thanks very much

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: quick xml write question

    just another quick question is there any way I can get the xml to display the image path like this

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <images>
    <pic>
    <image>my_images\116941_4039.jpg</image>

    </pic>
    </images>

    instead of the full path like this -

    <song path>"C:\Program Files\mgamerz\my_images\368041_2353.jpg" title="368041_2353.jpg"/>

    I had this problem whe I was dealing with mp3s but I have read the posts about it but I cannot work out how I can acheive it for this

    hope someone can help
    thanks in advance
    R

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: quick xml write question

    Try this...

    VB Code:
    1. Private Sub Command2_Click()
    2.     Dim f1 As Integer, jpgurl As String, MyPath As String, Artist As String, xmlpath As String, songpath As String, slidenode As String, songname As String, mp3path As String, f2 As Integer, i As Integer
    3.    
    4.  
    5.     Dim myFolder as string
    6.  
    7.     myFolder = "my_images\"
    8.     mp3path = "C:\Program Files\mgamerz\" & myFolder
    9.  
    10.      f2 = FreeFile
    11.     Open mp3path & "mp3.txt" For Output As #f2       ' if you don't need mp3.txt take out
    12.      f1 = FreeFile
    13.      
    14.     Open mp3path & "slides.xml" For Output As #f1
    15.     Print #f1, "<?xml version=""1.0""?>"
    16.     Print #f1, "<images>"
    17.     songname = Dir(mp3path & "\*.jpg")   ' get first track
    18.     i = 1
    19.     While Not Len(songname) = 0
    20.         Print #f1, "<photo>"
    21.  
    22.         Print #f1, "<image>";myfolder;songname;"</image>"
    23.  
    24.         Sleep 100                                ' slight pause, needed
    25.         songname = Dir                         ' get next track
    26.  
    27.         Print #f1, "</photo>"
    28.    
    29.     Wend
    30.     Print #f1, "</images>"
    31.  
    32. Close
    33. End Sub

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: quick xml write question

    brilliant - thanks.

    Just one other thing, for some of the properties required - I need to include this in the xml file but when I try and add it to my code to write it in the xml file my code messes up - it adds allsorts of qoutation marks and semi colons,

    I was thinking of bieng able to add text boxes so the user could input these values but I think that may be too advanced for me

    any ideas on this?

    <gallery timer="5" order="sequential" fadetime="2" looping="yes" xpos="0" ypos="0">

    thanks in advance
    R

  7. #7
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: quick xml write question

    To include quotes within a string, simply double them up.

    VB Code:
    1. Print #1, "<gallery timer=""5"" order=""sequential"" fadetime=""2"" looping=""yes"" xpos=""0"" ypos=""0"">"

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: quick xml write question

    thats great again thanks, would it be difficult to record values from text or check boxes into that info ie if looping is checked it will set it to yes or the timer on a text box?

    thanks again
    R

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