Jump to content

Search within XML file and remove certain data


Recommended Posts

Ok, so i have this XML file with a respectable number of lines in it. I want to search between the "<driver guid" and the "</driver>" and see if the "<source>" line has a "(?)" (?=number) in it. If it does, I want to delete everything from "<driver guid" to "</driver>" and continue to check the next set of "<driver guid" and "</driver>". I shortened the below code for sake of space, there are a random number of lines between "<driver guid" and "</driver>".

Any ideas?

<driver guid="{809f4069-0bbe-49cc-af58-4f75c296da74}" enable="True">
    <Name>NVIDIA Display nvdm.inf 7.15.10.9746</Name>
    <Manufacturer>NVIDIA</Manufacturer>
    <Version>7.15.10.9746</Version>
    <Source>.\Out-of-box Drivers\Display\nvd 7.15.10.9746\nvdm.inf</Source>
    <Type>Display</Type>
    <Platform>x86</Platform>
    <OSVersion>6.0</OSVersion>
    <PNPId>PCI\VEN_10DE&amp;DEV_00C8&amp;SUBSYS_019C1028</PNPId>
  </driver>
  <driver guid="{a24db7b9-ec1b-45dc-8245-7b33da7d579a}" enable="True">
    <Name>NVIDIA Display nvdm.inf 7.15.10.9746</Name>
    <Manufacturer>NVIDIA</Manufacturer>
    <Version>7.15.10.9746</Version>
    <Source>.\Out-of-box Drivers\Display\nvd 7.15.10.9746 (1)\nvdm.inf</Source>
    <Type>Display</Type>
    <Platform>x86</Platform>
    <OSVersion>6.0</OSVersion>
    <PNPId>PCI\VEN_10DE&amp;DEV_00C8&amp;SUBSYS_019C1028</PNPId>
  </driver>
Link to comment
Share on other sites

Here's a start... This is too complicated for a human to do with StringRegExpReplace..

$Read = FileRead("Source.txt")

$Line = StringSplit(StringStripCR($Read),@LF)

For $x = 1 To $Line[0]
    $Line[$x] = StringStripWS($Line[$x],1)
    
    $Prefix = StringTrimRight(StringTrimLeft(StringLeft($Line[$x],StringInStr($Line[$x],">")),1),1)
    Switch $Prefix
        Case "Source"
            MsgBox(0, "Source is on line " & $x, $Line[$x])
            If StringRegExp($Line[$x],"\([0-9]\)") Then
                MsgBox(0, "", "This part should be deleted, this is a StringRegExp match...")
            Else
                MsgBox(0, "", "This part should NOT be deleted.")
            EndIf
    EndSwitch
Next

The RegExp doesn't work yet though, my laptop batteries are dead.. Have to go and recharge.. :shocked:

Edited by Manadar
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...