Removes lines from xml file that match lines from a listPowershell: Error consuming WCF services with MTOM message encodingHow to use Powershell to return both filename and the matched text in the fileRead in two text file lists and write out 1 line from to a text filePowershell: Nested For Loops, returning 1 object from functionPowershell - XML source separation and customised descriptive preview for checkedlistbox listTroubles to extract informations from a specific list of filesReplace letters in list of txt files - powershellLooping through Multi Array with Wildcard powershellPowershell, Importing Registry Values from XMLPowerShell script to exclude a list of computers from getting disabled in AD

A food item only made possible by time-freezing storage?

Subverting the emotional woman and stoic man trope

Does the Horizon Walker ranger's Planar Warrior feature bypass resistance to non-magical attacks?

Could Apollo astronauts see city lights from the moon?

Is it acceptable to say that a reviewer's concern is not going to be addressed because then the paper would be too long?

There are 51 natural numbers between 1-100, proof that there are 2 numbers such that the difference between them equals to 5

What does מעלה עליו הכתוב mean?

Reorder a matrix, twice

Do we have any particular tonal center in mind when we are NOT listening music?

Medic abilities

What happens to a net with the Returning Weapon artificer infusion after it hits?

Top off gas with old oil, is that bad?

Algorithm that generates orthogonal vectors: C++ implementation

How to check if my quadrature encoder is broken or not?

What is the difference between an astronaut in the ISS and a freediver in perfect neutral buoyancy?

I transpose the source code, you transpose the input!

Windows 10 deletes lots of tiny files super slowly. Anything that can be done to speed it up?

Can I enter the UK without my husband if we said we'd travel together in our visa application?

MaxDetect speed

Would you write key signatures for non-conventional scales?

Youtube not blocked by iptables

How can I tell the difference between fishing for rolls and being involved?

How can this Stack Exchange site have an animated favicon?

Character Transformation



Removes lines from xml file that match lines from a list


Powershell: Error consuming WCF services with MTOM message encodingHow to use Powershell to return both filename and the matched text in the fileRead in two text file lists and write out 1 line from to a text filePowershell: Nested For Loops, returning 1 object from functionPowershell - XML source separation and customised descriptive preview for checkedlistbox listTroubles to extract informations from a specific list of filesReplace letters in list of txt files - powershellLooping through Multi Array with Wildcard powershellPowershell, Importing Registry Values from XMLPowerShell script to exclude a list of computers from getting disabled in AD






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I can't seems to figure out how to loop through an xml file and remove an entire "<option></option>" block that matches a lines from list. I know I need to loop through the xml file, then loop through the list. In the end I would replace the contents for the xml with the "filtered results".



XML file format:



<comboOptions>
<option value="1" text="MAINTYPE 1: SOME UNIQUE DESCRIPTION">
<option value="NOT_REQ" text="SUBTYPE NOT REQUIRED (NOT_REQ)"/>
</option>
<option value="13" text="MAINTYPE 2: SOME UNIQUE DESCRIPTION">
<option value="VALUE1" text="SUBTYPE 1: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE2" text="SUBTYPE 2: SOME UNIQUE DESCRIPTION"/>
</option>
<option value="11" text="MAINTYPE 5: SOME UNIQUE DESCRIPTION">
<option value="VALUE1" text="SUBTYPE 1: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE2" text="SUBTYPE 2: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE3" text="SUBTYPE 3: SOME UNIQUE DESCRIPTION"/>
</option>
<comboOptions>


My attempts so far:



[xml]$XmlFIle = Get-Content C:Pathtofile.xml

$RemoveList = @("MAINTYPE 1: SOME UNIQUE DESCRIPTION", "MAINTYPE 5: SOME UNIQUE DESCRIPTION")

ForEach ($option in $XmlFIle.comboOptions.option)
Where-Object $_ -notcontains $option.text


$XmlFIle.comboOptions.option | Foreach-Object
$myobj1 = $_.text
$RemoveList









share|improve this question
























  • It seems like you could just run $x.combooptions.option.where($_.text -in $removelist).removeall() to remove the attributes you don't need.

    – AdminOfThings
    Mar 28 at 19:28






  • 1





    This $XmlFile.comboOptions.option | Where-Object $RemoveList -contains $_.text | ForEach-Object $_.ParentNode.RemoveChild($_) should also do it

    – Theo
    Mar 28 at 19:32











  • @Theo your solution works with one minor change: -contains to -notcontains. Thank you!

    – cstafford
    Mar 28 at 19:49

















1















I can't seems to figure out how to loop through an xml file and remove an entire "<option></option>" block that matches a lines from list. I know I need to loop through the xml file, then loop through the list. In the end I would replace the contents for the xml with the "filtered results".



XML file format:



<comboOptions>
<option value="1" text="MAINTYPE 1: SOME UNIQUE DESCRIPTION">
<option value="NOT_REQ" text="SUBTYPE NOT REQUIRED (NOT_REQ)"/>
</option>
<option value="13" text="MAINTYPE 2: SOME UNIQUE DESCRIPTION">
<option value="VALUE1" text="SUBTYPE 1: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE2" text="SUBTYPE 2: SOME UNIQUE DESCRIPTION"/>
</option>
<option value="11" text="MAINTYPE 5: SOME UNIQUE DESCRIPTION">
<option value="VALUE1" text="SUBTYPE 1: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE2" text="SUBTYPE 2: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE3" text="SUBTYPE 3: SOME UNIQUE DESCRIPTION"/>
</option>
<comboOptions>


My attempts so far:



[xml]$XmlFIle = Get-Content C:Pathtofile.xml

$RemoveList = @("MAINTYPE 1: SOME UNIQUE DESCRIPTION", "MAINTYPE 5: SOME UNIQUE DESCRIPTION")

ForEach ($option in $XmlFIle.comboOptions.option)
Where-Object $_ -notcontains $option.text


$XmlFIle.comboOptions.option | Foreach-Object
$myobj1 = $_.text
$RemoveList









share|improve this question
























  • It seems like you could just run $x.combooptions.option.where($_.text -in $removelist).removeall() to remove the attributes you don't need.

    – AdminOfThings
    Mar 28 at 19:28






  • 1





    This $XmlFile.comboOptions.option | Where-Object $RemoveList -contains $_.text | ForEach-Object $_.ParentNode.RemoveChild($_) should also do it

    – Theo
    Mar 28 at 19:32











  • @Theo your solution works with one minor change: -contains to -notcontains. Thank you!

    – cstafford
    Mar 28 at 19:49













1












1








1








I can't seems to figure out how to loop through an xml file and remove an entire "<option></option>" block that matches a lines from list. I know I need to loop through the xml file, then loop through the list. In the end I would replace the contents for the xml with the "filtered results".



XML file format:



<comboOptions>
<option value="1" text="MAINTYPE 1: SOME UNIQUE DESCRIPTION">
<option value="NOT_REQ" text="SUBTYPE NOT REQUIRED (NOT_REQ)"/>
</option>
<option value="13" text="MAINTYPE 2: SOME UNIQUE DESCRIPTION">
<option value="VALUE1" text="SUBTYPE 1: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE2" text="SUBTYPE 2: SOME UNIQUE DESCRIPTION"/>
</option>
<option value="11" text="MAINTYPE 5: SOME UNIQUE DESCRIPTION">
<option value="VALUE1" text="SUBTYPE 1: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE2" text="SUBTYPE 2: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE3" text="SUBTYPE 3: SOME UNIQUE DESCRIPTION"/>
</option>
<comboOptions>


My attempts so far:



[xml]$XmlFIle = Get-Content C:Pathtofile.xml

$RemoveList = @("MAINTYPE 1: SOME UNIQUE DESCRIPTION", "MAINTYPE 5: SOME UNIQUE DESCRIPTION")

ForEach ($option in $XmlFIle.comboOptions.option)
Where-Object $_ -notcontains $option.text


$XmlFIle.comboOptions.option | Foreach-Object
$myobj1 = $_.text
$RemoveList









share|improve this question














I can't seems to figure out how to loop through an xml file and remove an entire "<option></option>" block that matches a lines from list. I know I need to loop through the xml file, then loop through the list. In the end I would replace the contents for the xml with the "filtered results".



XML file format:



<comboOptions>
<option value="1" text="MAINTYPE 1: SOME UNIQUE DESCRIPTION">
<option value="NOT_REQ" text="SUBTYPE NOT REQUIRED (NOT_REQ)"/>
</option>
<option value="13" text="MAINTYPE 2: SOME UNIQUE DESCRIPTION">
<option value="VALUE1" text="SUBTYPE 1: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE2" text="SUBTYPE 2: SOME UNIQUE DESCRIPTION"/>
</option>
<option value="11" text="MAINTYPE 5: SOME UNIQUE DESCRIPTION">
<option value="VALUE1" text="SUBTYPE 1: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE2" text="SUBTYPE 2: SOME UNIQUE DESCRIPTION"/>
<option value="VALUE3" text="SUBTYPE 3: SOME UNIQUE DESCRIPTION"/>
</option>
<comboOptions>


My attempts so far:



[xml]$XmlFIle = Get-Content C:Pathtofile.xml

$RemoveList = @("MAINTYPE 1: SOME UNIQUE DESCRIPTION", "MAINTYPE 5: SOME UNIQUE DESCRIPTION")

ForEach ($option in $XmlFIle.comboOptions.option)
Where-Object $_ -notcontains $option.text


$XmlFIle.comboOptions.option | Foreach-Object
$myobj1 = $_.text
$RemoveList






powershell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 18:10









cstaffordcstafford

871 gold badge1 silver badge8 bronze badges




871 gold badge1 silver badge8 bronze badges















  • It seems like you could just run $x.combooptions.option.where($_.text -in $removelist).removeall() to remove the attributes you don't need.

    – AdminOfThings
    Mar 28 at 19:28






  • 1





    This $XmlFile.comboOptions.option | Where-Object $RemoveList -contains $_.text | ForEach-Object $_.ParentNode.RemoveChild($_) should also do it

    – Theo
    Mar 28 at 19:32











  • @Theo your solution works with one minor change: -contains to -notcontains. Thank you!

    – cstafford
    Mar 28 at 19:49

















  • It seems like you could just run $x.combooptions.option.where($_.text -in $removelist).removeall() to remove the attributes you don't need.

    – AdminOfThings
    Mar 28 at 19:28






  • 1





    This $XmlFile.comboOptions.option | Where-Object $RemoveList -contains $_.text | ForEach-Object $_.ParentNode.RemoveChild($_) should also do it

    – Theo
    Mar 28 at 19:32











  • @Theo your solution works with one minor change: -contains to -notcontains. Thank you!

    – cstafford
    Mar 28 at 19:49
















It seems like you could just run $x.combooptions.option.where($_.text -in $removelist).removeall() to remove the attributes you don't need.

– AdminOfThings
Mar 28 at 19:28





It seems like you could just run $x.combooptions.option.where($_.text -in $removelist).removeall() to remove the attributes you don't need.

– AdminOfThings
Mar 28 at 19:28




1




1





This $XmlFile.comboOptions.option | Where-Object $RemoveList -contains $_.text | ForEach-Object $_.ParentNode.RemoveChild($_) should also do it

– Theo
Mar 28 at 19:32





This $XmlFile.comboOptions.option | Where-Object $RemoveList -contains $_.text | ForEach-Object $_.ParentNode.RemoveChild($_) should also do it

– Theo
Mar 28 at 19:32













@Theo your solution works with one minor change: -contains to -notcontains. Thank you!

– cstafford
Mar 28 at 19:49





@Theo your solution works with one minor change: -contains to -notcontains. Thank you!

– cstafford
Mar 28 at 19:49












0






active

oldest

votes














Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404278%2fremoves-lines-from-xml-file-that-match-lines-from-a-list%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55404278%2fremoves-lines-from-xml-file-that-match-lines-from-a-list%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript