Extract specific data from xml with batch

December 17, 2010 at 00:17:07
Specs: Windows XP
Hi guys
I'm new here and have been looking everywhere but cannot find a solution.
What I need to do is extract specific data from an xml file and have it output to a text file.
Here is an example of the file I need info from:

<?xml version="1.0" encoding="UTF-8" ?>
- <version number="1" fileVersion="3">
- <folderInfo>
<name>C:/DATA (new)/Operations</name>
<utc-date>1276035506</utc-date>
<attributes>24</attributes>
</folderInfo>
- <folderInfo>
<name>C:/DATA (new)/Operations/Accounting</name>
<utc-date>1276034025</utc-date>
<attributes>24</attributes>
</folderInfo>
- <folderInfo>
<name>C:/DATA (new)/Operations/Accounting/Accounting Bkg</name>
<utc-date>1276034312</utc-date>
<attributes>24</attributes>
</folderInfo>
- <fileInfo flags="0">
<name>C:/DATA (new)/Operations/Accounting/Accounting Bkg/Cash Flow projections.xls</name>
<utc-date>1223866675</utc-date>
<attributes>0</attributes>
- <chunk name="6e911eb0-a24c-409d-ad7b-fd518a60c4f6" size="85504" storedSize="24850" flags="5" checksum="26583">
<md5>XMNntFZ/oXwKErrFdibB9Q==</md5>
<sha1>EIz2i9bUys9xKvV0Gb9J+ME5geQ=</sha1>
<storedmd5>UCCfcYY+2zJ8Of/q3W6HrQ==</storedmd5>
</chunk>
</fileInfo>

In the above info I have to extract all the "chunk name" data and list it in a new text file.
Is there a way I could create a batch file to do this?
I have multiple xml files and each file has over 200 "chunk name" data listings in them


See More: Extract specific data from xml with batch

Report •


#1
December 17, 2010 at 02:16:09
find "chunk name" < myfile > newfile


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
December 17, 2010 at 02:53:09
That created a txt file with the full contents of the the .xml file. It did not extract just the "chunk name" data. That is the issue I have been having. I don't understand why I can't extract the specific info.

Report •

#3
December 17, 2010 at 02:58:39
Here are the the scripts that I have tried:

for %%T in (*.xml) do find "chunk name" < %%T >> chunk_names.txt


find "chunk name=" < version-1.xml > chunk_name.txt

both of these create a text file of the full contents of the xml


Report •

Related Solutions

#4
December 17, 2010 at 04:22:46
I get just the expected line.

My guess is that this form tweaks your post enough to throw a wrench in the works.

Maybe ZIP the file and put it on a share site or send it to me using http://sendthisfile.com or similar.


=====================================
Life is too important to be taken seriously.

M2


Report •

#5
December 17, 2010 at 04:41:42
In this line:

- <chunk name="6e911eb0-a24c-409d-ad7b-fd518a60c4f6" size="85504" storedSize="24850" flags="5" checksum="26583">

the info I need is inside the quotes:
6e911eb0-a24c-409d-ad7b-fd518a60c4f6

is there a way to extract just that? The xml files have many of them and they are all different. I basically need to list that specific info

I will try to send you the file


Report •

#6
December 17, 2010 at 04:55:19
This is the script I want to use (it has a user interface so I can change the file I'm extracting from)


@Echo Off
:LOOP
ClS
Echo.
Set /P File=Enter File Name ^>
Set /P Text=Enter text to extract^>
Echo.
Echo.All text "%Text%" will be extracted from %File%
Set /P Answ=Enter Y/y to proceed^>
If /I not "%Answ%"=="Y" GoTo :LOOP

Find "%Text%" "%File%" > "%File%_%Text%".txt
Echo.File %File%_%Text%.txt created
Echo.
Echo.Close batch file?
Set /P Exit=Enter Y/y to exit^>
Echo.
If /I not "%Exit%"=="Y" GoTo :LOOP

Set Text=
Set File=
Set Answ=
set Exit=
::End_Of-Batch


Report •

#7
December 17, 2010 at 04:58:02
I sent you the file

Report •


Ask Question