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 140947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:41:51+00:00 2026-05-11T07:41:51+00:00

I’m still playing around with xml. Now I have a file that looks like

  • 0

I’m still playing around with xml. Now I have a file that looks like this:

<?xml version='1.0' encoding='utf-8'?> <Attributes>  <AttributeSet id='10110'>   <Attribute id='1'>some text here</Attribute>   <Attribute id='2'>some text here</Attribute>   <!-- 298 more Attribute nodes follow -->   <!-- note that the value for the id attribute is numbered consecutively -->  </AttributeSet> </Attributes> 

There are 300 Attribute nodes total, most of which I don’t need. What I’d like to do is remove all Attribute nodes that don’t have a specified value for the id attribute. I have established a string array with about 10 values. These values represent the attributes that I’d like to keep in the xml. The rest I’d like to remove.

What I’m trying to do with the code below is modify the xml by removing all Attribute nodes that I don’t want to use:

Dim ss() As String = New String() {'39', '41', '38', '111', '148', '222', '256', '270', '283', '284'} 'keep the Attributes whose id value is one of these numbers Dim rv As New List(Of String)'will hold Attribute ids to remove Dim bool As Boolean = False For Each x As XElement In doc...<eb:Attribute>  For Each s As String In ss   If x.@id = s Then    bool = True    Exit For   End If  Next  If bool = True Then   'do nothing  Else 'no attribute matched any of the attribute ids listed mark xelement for removal   rv.Add(x.@id)  End If Next 'now remove the xelement For Each tr As String In rv  Dim h As String = tr  doc...<eb:Attribute>.Where(Function(g) g.@id = h).Remove() Next 'save the xml doc.Save('C:\myXMLFile.xml') 

For some reason, my code doesn’t work. None of the undesired Attribute nodes are removed.

What’s the problem? How can I remove the Attribute nodes whose id attribute values don’t match any number in my string array?

Thanks in advance.

P.S. – I hope I made myself clear in describing my problem.

  • 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. 2026-05-11T07:41:52+00:00Added an answer on May 11, 2026 at 7:41 am

    Never mind. I figured it out. Here what I did:

    For Each x As XElement In doc...<eb:Attribute>  **bool = False 'I simply added this line of code and everything worked perfectly**  For Each s As String In ss   If x.@id = s Then    bool = True    Exit For   End If  Next  If bool = True Then   'do nothing  Else 'no attribute matched any of the attribute ids listed so remove the xelement   rv.Add(x.@id)  End If Next 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.