# Want to parse/edit XML file, which (easy) language shoul I use?

Discussion in 'Mixed Languages' started by johnye_pt, Dec 9, 2019.

Aug 26, 2010
711
341
30
I know my way around batch files, and have dipped my toes in VBScript about 10 years ago. Can any of these two play around with XML files, or do I need to learn another language? Batch files are limited due to the usual problems with special characters like !,%,etc and no native support for XML, and I don't know if VBScript even supports XML.

Basically what I want to do is parse a XML file and apply some "conditions" to remove similar entries which are not exactly the same name, but repeated nonetheless. The "conditions" will determine which one stays and which ones are deleted. For example, if I want to keep all entries with "(abc)", then "text (abc)" stays and "text (def)" is deleted.

2. ### Thomas Dubreuil MDL Senior Member

Aug 29, 2017
356
588
10
I wouldn't recommend using batch for parsing XML data.
Use a language (like powershell, for instance) that natively supports such data formats...

Here's a good start: https://devblogs.microsoft.com/scri...fe-learns-to-use-powershell-to-work-with-xml/
In PS (if I simplify to the extrem) you can do something like this...
Code:
[xml]$XML_File = Get-Content "path\to\yourfile.xml"$XML_File.container1.container2 | % {
$1st_valuetoparse =$_.1st_valuetoparse
$2nd_valuetoparse =$_.2nd_valuetoparse
If ($1st_valuetoparse -eq "abcdef") {$1st_valuetoparse = "abc"}
If ( ($2nd_valuetoparse -eq "abcdef" -or ($2nd_valuetoparse -like "*def*") ) {$2nd_valuetoparse = "abc"}$Object = [pscustomobject][ordered]@{
"1stvaluetoparse"   =  "$1st_valuetoparse " "2nd_valuetoparse" = "$2nd_valuetoparse"
}
$Object | Export-Csv "$PSScriptRoot\parsedfile.csv" -delimiter "t" -NoTypeInformation -Append
}`

Set "container(s)" and "valuetoparse" according to your xml of course, that's just very basic example to get you started...
Might be better if you give an example of your xml file and what to keep in scripting subforum if you need more precise help.

Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Aug 26, 2010
711
341
30
#3 (OP)
I thought about using Powershell, but I already tried learning it once or twice and found it too confusing. Maybe I'm not as young as I once was and learning a new language at this point is just too time consuming for me. I googled a bit about VBScript and XML and it seems it can also parse XMLs, probably not as "simple" as with PowerShell but since I already used VBScript before it would be easier for me to "relearn". I just don't if it has the same limitations as Batches do when dealing with variables containing parenthesis, "%" and "!", as some strings I want to compare have them.

4. ### K4onashi MDL Debugger

Mar 7, 2012
1,815
1,988
60
I'd suggest VB.NET in visual studio community if you used VBS. If you need any help let me know, I'll see what I can do as I've lots of experience with XML dabbling.

Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...