Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Write to File batch script


  • Please log in to reply
3 replies to this topic

#1 supawiz6991

supawiz6991

  • Members
  • 75 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:05:28 PM

Posted 19 March 2012 - 10:21 AM

Hello,

I am in the beginning stages of writing a batch script to write out information to an XML file. From the research I've done, the consensus is that writing out to a xml file with a batch script is painful. Other than that though I haven't found any useful information on how to do it.

I work for a radio station and the xml file I would like to write to is used for transmitting now playing information to our website widget.

The data inside the xml looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<nexgen_audio_export>

<audio ID="id_000000000_00000000">
<type>Song</type>
<status>Playing</status>
<artist>Artist</artist>
<title>Song Name</title>
<length_in_secs>00003600</length_in_secs>
</audio>

</nexgen_audio_export>

The file is on a local machine in the C directory. Any ideas on how I can write this data to an XML file?

Thanks,
Supawis6991

BC AdBot (Login to Remove)

 


#2 Nate15329

Nate15329

  • Members
  • 92 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:WI, USA
  • Local time:04:28 PM

Posted 22 March 2012 - 12:55 PM

use escape char ^ before each < >

like this in batch:

echo ^<?xml version="1.0" encoding="ISO-8859-1"?^> >> file.xml
echo ^<nexgen_audio_export^> >> file.xml

set id2=000000
set id1=000001
set type=song
set status=playing
set artist=artist
set title=mytitle
set length=00003600

echo ^<audio ID="id_%id2%_%id1%"^> >> file.xml
echo ^<type^>%type%^</type^> >> file.xml
echo ^<status^>%status%^</status^> >> file.xml
echo ^<artist^>%artist%^</artist^> >> file.xml
echo ^<title^>%title%^</title^> >> file.xml
echo ^<length_in_secs^>%length%^</length_in_secs^> >> file.xml
echo ^</audio^> >> file.xml


echo ^</nexgen_audio_export^> >> file.xml


Edit: I suggest making it better for automation, i just quickly made this.

Edited by Nate15329, 22 March 2012 - 01:02 PM.


#3 muhuwj201

muhuwj201

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Local time:05:28 PM

Posted 05 April 2012 - 12:29 PM

I use this :
@echo off
echo <type>Song</type> >>> file.xml
echo <title>My Song</type> >>> file.xml
echo Done!

Edited by muhuwj201, 05 April 2012 - 12:29 PM.


#4 dnthns87

dnthns87

  • Members
  • 27 posts
  • OFFLINE
  •  
  • Local time:05:28 PM

Posted 08 April 2012 - 06:06 AM

Redirect the output to a text file.

> Will create a new text file and echo the line into it.
>> Will echo the line into a already existing text file.


Example:

echo Line1>%tmp%\tmp
echo Line2>>%tmp%\tmp





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users