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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:17:03+00:00 2026-06-08T15:17:03+00:00

I am trying to check whether or not a string is exists in an

  • 0

I am trying to check whether or not a string is exists in an xml file. If it does not exist, I have to add that string to the xml file.

My xml file looks like this:

  <Employee>
      <Emp>
        <Name id="1">   A     </Name>
        <Name id="2">   C     </Name>
        <Name id="3">   D     </Name>
       </Emp>
  </Employee>

And I want achieve:

dim str as string = "b" 
if str exists in "xmlfile"
    'do something
else
    'add string to file
end if

I am not really familiar LINQ at all but I understand that what I want to do is possible with LINQ. I have tried the following:

Dim employee = XElement.Load(someStream)
Dim emp = employee.Element("Emp")
If emp IsNot Nothing Then
    else
        'add string to xml file
End If

When I tried this I received the error: XElement is not declared.

Can any one suggest a way to do what I want in VB.NET without LINQ? Or if I have to use LINQ, can some provide an example?

I am using .net 2.0 (VB.NET)

  • 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-08T15:17:06+00:00Added an answer on June 8, 2026 at 3:17 pm

    What I think you want is something more like this:

    Dim employeeData As XDocument
    Dim employeeElements as List(Of XElement)
    Dim numberOfNames as Integer = 0
    
    employeeData = XDocument.Load(someStream)
    
    employeeElements = (From elements In employeeData.Decendants()
                        Where (elements.Name.LocalName.ToString() = "Emp")
                        Select elements).ToList()
    
    For Each employee In employeeElements
        If (employee.<Name>.Value = "B") Then
            numberOfNames = numberOfNames + 1
        End If
    Next
    
    If numberOfNames > 0 Then
        'Insert "B" into xml
    End If
    

    So that’s an example using XDocument and interating though like user1512185 suggested with an example LINQ expression to get a list of XElements to iterate through.

    This is a modification of something I do in one of my apps. However I don’t insert into the xml so I’m not sure I can help you there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a function that can check whether or not some
Like Python? I'm trying to check whether each character in a string is an
I'm trying to check whether a $_POST exists and if it does, print it
I have been trying to check whether an NSInteger is odd or even. I
I'm trying to check if a file exists. If I use this: NSData *data
I'm trying to check whether or not the second argument in my program is
I'm trying to check whether val() has a specific value or not inside a
I am trying to do a basic operation: to check whether string is a
I am using an if statement to check whether an XML object exists, but
can anyone help me in trying to check whether JavaScript is enabled in client

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.