How to make syntax work to extract exact number from XMLfile

February 12, 2018 at 11:50:24
Specs: Windows 8
i need to extract the number beside the single id
<?xml version="1.0" encoding="utf-8"?>
<single id="892131748483" country="us" language="en">
<title>Finding the Ratio between One Quantity and the Total Number in a Word Problem</title>

to exact location in another bat file


See More: How to make syntax work to extract exact number from XMLfile

Reply ↓  Report •

#1
February 12, 2018 at 18:43:45
You need just extract this 892131748483 ? and set it into a variable ?
Give a try for this batch file :

@echo off
Call :Extract "Test.xml" ID
echo ID = %ID%
pause & exit
::----------------------------------------------------------------------------
:Extract <InputData> <Variable_To_Extract>
(
echo Data = WScript.StdIn.ReadAll
echo Data = Extract(Data,"\d{12}"^)
echo WScript.StdOut.WriteLine Data
echo Function Extract(Data,Pattern^)
echo    Dim oRE,oMatches,Match,Line
echo    set oRE = New RegExp
echo    oRE.IgnoreCase = True
echo    oRE.Global = True
echo    oRE.Pattern = Pattern
echo    set oMatches = oRE.Execute(Data^)
echo    If not isEmpty(oMatches^) then
echo        For Each Match in oMatches  
echo            Line = Line ^& Trim(Match.Value^) ^& vbcrlf
echo        Next
echo        Extract = Line
echo    End if
echo End Function
)>"%Temp%\%~n0.vbs"
for /f "delims=" %%a in ('cscript //nologo "%Temp%\%~n0.vbs" ^< "%~1"') do (
	Set "%2=%%a"
)
Del "%Temp%\%~n0.vbs"
goto :eof
::----------------------------------------------------------------------------

message edited by Hackoo


Reply ↓  Report •
Related Solutions


Ask Question