|
-
Oct 18th, 2005, 04:45 PM
#1
Thread Starter
Hyperactive Member
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:
Private Sub Command2_Click()
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
mp3path = "C:\Program Files\mgamerz\my_images\"
f2 = FreeFile
Open mp3path & "mp3.txt" For Output As #f2 ' if you don't need mp3.txt take out
f1 = FreeFile
Open mp3path & "slides.xml" For Output As #f1
Print #f1, "<?xml version=""1.0""?>"
Print #f1, "<images>"
Print #f1, "<pic>"
songname = Dir(mp3path & "\*.jpg") ' get first track
i = 1
While Not Len(songname) = 0
MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath) + 1)) & " " & songname
songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & songname & """/> "
Print #f1, songpath
Print #f2, songname ' for mp3.txt
Sleep 100 ' slight pause, needed
songname = Dir ' get next track
Wend
Print #f1, "</pic>"
Print #f1, "</images>"
Close
End Sub
hope someon can shed some light
thanks in advance
R
-
Oct 18th, 2005, 06:04 PM
#2
Re: quick xml write question
Move the printing of the Photo and Image tags into the While loop.
VB Code:
Private Sub Command2_Click()
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
mp3path = "C:\Program Files\mgamerz\my_images\"
f2 = FreeFile
Open mp3path & "mp3.txt" For Output As #f2 ' if you don't need mp3.txt take out
f1 = FreeFile
Open mp3path & "slides.xml" For Output As #f1
Print #f1, "<?xml version=""1.0""?>"
Print #f1, "<images>"
songname = Dir(mp3path & "\*.jpg") ' get first track
i = 1
While Not Len(songname) = 0
Print #f1, "<photo>"
Print #f1, "<image>"
Print #f1, mp3path & songname
Sleep 100 ' slight pause, needed
songname = Dir ' get next track
Print #f1, "</image>"
Print #f1, "</photo>"
Wend
Print #f1, "</images>"
Close
End Sub
-
Oct 18th, 2005, 10:09 PM
#3
Thread Starter
Hyperactive Member
Re: quick xml write question
-
Oct 18th, 2005, 10:14 PM
#4
Thread Starter
Hyperactive Member
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
-
Oct 19th, 2005, 01:29 PM
#5
Re: quick xml write question
Try this...
VB Code:
Private Sub Command2_Click()
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
Dim myFolder as string
myFolder = "my_images\"
mp3path = "C:\Program Files\mgamerz\" & myFolder
f2 = FreeFile
Open mp3path & "mp3.txt" For Output As #f2 ' if you don't need mp3.txt take out
f1 = FreeFile
Open mp3path & "slides.xml" For Output As #f1
Print #f1, "<?xml version=""1.0""?>"
Print #f1, "<images>"
songname = Dir(mp3path & "\*.jpg") ' get first track
i = 1
While Not Len(songname) = 0
Print #f1, "<photo>"
Print #f1, "<image>";myfolder;songname;"</image>"
Sleep 100 ' slight pause, needed
songname = Dir ' get next track
Print #f1, "</photo>"
Wend
Print #f1, "</images>"
Close
End Sub
-
Oct 19th, 2005, 01:40 PM
#6
Thread Starter
Hyperactive Member
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
-
Oct 19th, 2005, 02:06 PM
#7
Re: quick xml write question
To include quotes within a string, simply double them up.
VB Code:
Print #1, "<gallery timer=""5"" order=""sequential"" fadetime=""2"" looping=""yes"" xpos=""0"" ypos=""0"">"
-
Oct 19th, 2005, 02:54 PM
#8
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|