Validate tags for the xml files

July 26, 2018 at 08:47:54
Specs: Windows 7
Please guide me on how to achieve this, I am not sure if it’s possible in batch scripting.
I have a directory (c:\TDR) in which I have some xml files (it can be 10 or 20 or 100).

In each xml file for every TDRNO I have to check if the below tags are missing, or if these tags are present then it should not be null or blank.

List of tags which I am trying to check: - Name, Line1, Line2, Line3, City

If Tags are missing or if it’s blank then, I am trying to generate a separate output file with the filename, TDRNo, and the list of tags which are missing

Sample Xml source file.

<?xml version="1.0" encoding="windows-1252"?>
<Correspondence xmlns="" xmlns:xsi="" xsi:noNamespaceSchemaLocation="C:\TDR\migration\XML_XSD\TDR_Static.xsd">
<Name>TDR Company</Name>
<Line1> 7255 Sunset Ave</Line1>
<City> Las Vegas</City>
<Line1> </Line1>
<Line3> </Line3>
<Line4> </Line4>
<City> St.Louis</City>

I am trying to check the above, with the below script, I updated from the existing code I got from online but I am not sure if this is the correct way of doing it. Please provide me some ideas on how to do this.

@echo off & setlocal enabledelayedexpansion

cd c:\TDR
for %%x in (*.xml) do

if not exist "Line1%" goto MissingTags
goto TagsPresent

echo "Line1 is not Present" > c:\TDR\XmlValidation.txt

exit /b 0

copy c:\TDR\*.xml c:\TDR\Validated

exit /b 0

message edited by Taarini

See More: Validate tags for the xml files

Report •

July 26, 2018 at 20:07:52
Hi Taarini , Did you find any solution, I am also looking for a similar script. Please share if you found something.

Report •

July 27, 2018 at 07:26:50
What you posted is not valid XML. You open tags for "TDRActivity" without any close tags, and you have close tags for "TDR" without any open tags.

How To Ask Questions The Smart Way

Report •

August 2, 2018 at 11:21:53
Sorry, there was some issue in copy and paste, so I typed. it is a typo.

Thanks for your time.

message edited by Taarini

Report •

Related Solutions

August 2, 2018 at 11:23:34
I think its not possible in doing in batch scripting, I have created a script which will convert xml to csv file and from the csv file I am reading it in datastage and finding the tags which are missing or with blank value.

Please let me know if you like me to send the xml to csv convention script

Report •

Ask Question