Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8732805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:30:30+00:00 2026-06-13T09:30:30+00:00

I have something similar to the following in an XML document: <variables> <variable> <name>ctrl_btn</name>

  • 0

I have something similar to the following in an XML document:

<variables>
    <variable>
        <name>ctrl_btn</name>
        <value>button</value>
    </variable>
    <variable>
        <name>ctrl_snpt_calctrl</name>
        <value>The date entered must be less than or equal to</value>
    </variable>
</variables>

I am able to use Powershell to pull out certain elements within the document (such as grabbing the name or value element based on an index number). However, I don’t follow how those indices work (or whatever the indices may be called). For example, look for name[1] gives me ctrl_btn, but I would have assumed that would be name[0]. Could someone explain that?

My real problem, however, is creating a script that removes certain collections of elements within the document. For example, if I want to remove the following:

    <variable>
        <name>ctrl_snpt_calctrl</name>
        <value>The date entered must be less than or equal to</value>
    </variable>

I have searched around, but most examples only remove a certain node from the XML and not a whole group as the above.

The name and value are always unique within the XML document (which, by the way, contains over 5000 different name/value combos in the <variable></variable> element.

The list of elements I want to remove are contained within a text file that lists only the name value (e.g., the text document would list ctrl_btn and then ctrl_snpt_calctrl).

To give you better idea, here’s the whole process that the script does:

  1. Get the content of the XML document
  2. Get the value between the <name></name> elements for all items in the document
  3. A search is run against a list of files to verify that the name is used within the file.
  4. If the name is not used, it is written a text file (e.g., not_found.txt).
  5. Remove the <variable></variable> tags and everything between them if the ` is equal to the name found in the not_found.txt.

I’m not sure if the process above helps with an explanation, but I thought I better include it.

So how do you remove these?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:30:32+00:00Added an answer on June 13, 2026 at 9:30 am

    Assuming you have a string array with each element being the name of a variable element you want to remove, you could do the following:

    $names = 'ctrl_btn','ctrl_snpt_calctrl'
    
    $xml.variables.variable | ? { $names -contains $_.name } | % {$xml.variables.RemoveChild($_)}
    

    I am able to use Powershell to pull out certain elements within the document (such as grabbing the name or value element based on an index number). However, I don’t follow how those indices work (or whatever the indices may be called). For example, look for name[1] gives me ctrl_btn, but I would have assumed that would be name[0]. Could someone explain that?

    Xml order is not guaranteed, so don’t rely on this. On my machine, for example, I get the results you expect:

    $xml.variables.variable.name[0] = ctrl_btn
    
    $xml.variables.variable.name[1] = ctrl_snpt_calctrl
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using the following xpath selection in xpath 1.0 <xsl:variable name=id><xsl:value-of select=./@id
i have something similar to the following... used a python script to JSON to
I have an ASP.NET web site with something similar to the following code: .aspx
We currently have an ant task that contains something similar to the following: <filelist
I want to output something similar to the following using XSLT XML: <myroot> <node1>
I have something similar to the following selector: $('div, span', $('.test')).selector I expect the
I'm new to Entity Framework. :-) I have something similar to the following: Master
I have the following xml snippets: <CreditCard name=John Doe ccnum=1234123412341234 ccv=239 exp=03/13> </CreditCard> <CreditCard>
Let's say I have the following XML file <a id=123> <b type=foo value=1 />
I have the following XML: <A> <B> <C Since=2011-09-26T11:12:41.1383089Z> <E Name=One AnotherDate=2011-09-26T10:54:05.7025781Z/> <E Name=Two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.