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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현