0

Can anyone help to write the BATCH program to read the tag element value from XML file and if that value matched with the one you need then export the name of XML file to Excel.

suppose in folder there are 20 XML files, this script should read the specific tag element value from XML file and based on that it should export the XML file name to excel/csv/txt. so may be output txt/csv/excel file will have 5 xml file name which matches your criteria

ex. Folder TEST have 20 XML files, test1.xml, test2.xml and so on...

test1.xml sample would be like below...we need to check value and based on that export the name of the file to text/csv/excel.....

 <?xml version="1.0" encoding="UTF-8"?>
-<sh:StandardBusinessDocumentHeader>
    <sh:HeaderVersion>1.0</sh:HeaderVersion>
    -<sh:Sender>
        <sh:Identifier>3015060500992</sh:Identifier>
    </sh:Sender>
    -<sh:Receiver>
        <sh:Identifier>4539594000005</sh:Identifier>
    </sh:Receiver>
    -<sh:DocumentIdentification>
        <sh:Standard>EAN.UCC</sh:Standard>
        <sh:TypeVersion>2.5</sh:TypeVersion>
        <sh:InstanceIdentifier>SBDH_4539594000005_tt7x7c71fof8d9adenhr</sh:InstanceIdentifier>
        <sh:Type>multiShipmentOrder</sh:Type>
        <sh:MultipleType>false</sh:MultipleType>
        <sh:CreationDateAndTime>2013-04-09T11:08:54</sh:CreationDateAndTime>
    </sh:DocumentIdentification>
</sh:StandardBusinessDocumentHeader>

Regards, Parag

2
  • 1
    read the specific tag element value which one? Commented Sep 5, 2013 at 6:43
  • Don't do that in a batch file. Commented Sep 5, 2013 at 7:39

1 Answer 1

0

try this

@echo off
echo. >export.txt
set searchid="<sh:InstanceIdentifier>SBDH_4539594000005_tt7x7c71fof8d9adenhr<"
for /f %%a in ('findstr /i /m %searchid% *.xml') do (
  echo %%a >>export.txt
)
Sign up to request clarification or add additional context in comments.

3 Comments

Hi,Got one more issue....I am doing find string from folder which has "!" in the folder name....ex... based on above script on line no 5 if we have folder name like this 'findstr /i /m %searchid% c:\ABC!def*.xml' ; it would not return anything. Could you please help how to consider the folder name having special character in it.
Hi, any idea how to handle special character ! in folder name
Try quoting the name, if that does not work, I suggest you open a new SO question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.