Search in XML files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Search in XML files

#1 Post by zagix » 14 Jul 2016 21:23

Hi,

I have multiples of XML files in folder c:/xml and need to search for a numeric value or string, without opening the files and once the value is located then display the particular file name on console, condition is that it should run the search on all the xml files and output the search result on console.

Thanks in advance.

Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Search in XML files

#2 Post by Aacini » 14 Jul 2016 21:30

Code: Select all

findstr /M "search string" c:\xml\*.xml

Antonio

zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Re: Search in XML files

#3 Post by zagix » 14 Jul 2016 21:46

Hi,

Thanks Aacini.

zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Re: Search in XML files

#4 Post by zagix » 15 Jul 2016 13:54

Hi,

Aacini, i need some more help.

Search value in c:\xml and its sub folders, and if value is found in any of xml file then get the tag <clntId> and <priority> values on the console.

Thanks in advance.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Search in XML files

#5 Post by foxidrive » 16 Jul 2016 04:54

zagix wrote:Aacini, i need some more help.

Search value in c:\xml and its sub folders, and if value is found in any of xml file then get the tag <clntId> and <priority> values on the console.


Give your task a good think and then help Aacini to help you by giving him your entire task in one go.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Search in XML files

#6 Post by aGerman » 16 Jul 2016 10:06

zagix

Batch doesn't support XML parsing.

Code: Select all

<foo>123</foo><bar>abc</bar>

... is the same as ...

Code: Select all

<foo>123</foo>
<bar>abc</bar>

... and both valid parts in an XML file.
We would need to know the entire content of such an XML file. Then we could decide what language or hybrid script could be applicable to read the values.

Regards
aGerman

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Search in XML files

#7 Post by Compo » 16 Jul 2016 17:34

If you dont mind using powershell and can follow the method used here
you could change the second line to:

Code: Select all

$Files = ls $Path -R -I *.xml | Select-String "My Search String" -list | % { $_.path }
…and see how you go!

zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Re: Search in XML files

#8 Post by zagix » 20 Jul 2016 22:03

Hi,

Compo, on testing i am getting this error.

Code: Select all

PS C:\Users\S> C:\Test\LatLonAlt.ps1
Get-Content : Cannot bind argument to parameter 'Path' because it is null.
At C:\Test\LatLonAlt.ps1:11 char:32
+    [XML] $Content = Get-Content <<<<  $File.FullName
    + CategoryInfo          : InvalidData: (:) [Get-Content], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetContentCommand

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Search in XML files

#9 Post by foxidrive » 21 Jul 2016 03:15

I'd like to make an observation that technical forums such a dostips have an element of social interaction in them also and it's not all that pleasant to see people arrive to ask a question and then ignore those other people who have taken the time to make comments or provide code or suggestions.

This happens far too often in modern days and I become grumpy; as within me it amounts to rudeness on the part of people seeking free help to save themselves some time.



When batch scripting was the sole domain of enthusiasts who were learning how to wring new abilities out of MSDOS it was a very respectful and friendly environment. The new things in modern days are the frequent arguments, and the unwillingness to provide details about a task, and getting an answer and shooting through with no comment at all.

There weren't many places you could natter about batch files in those past times so multi-posting wasn't around then either.

I should tattoo a slogan on my forehead saying "Grumpy old fart." ;)

Post Reply