• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 61
  • Last Modified:

Handle Ampersand in XML Linq

I am trying to do a LINQ query and have a field that has an Ampersand rendered as &
<StateSpecialty stateKey="Alabama" specialtyKey="L&D" stateName="Alabama" state="AL" specialty="L&D" specialtyMarketing="Labor & Delivery">

For the life of me I cannot get the query to work

Below...I've passed in for _specialty
L&D
L%26D
And..the actual string    L&D
Nothing seems to work

            Dim regionElements = From r In doc.Descendants("StateSpecialty") _
                                 Where r.Attribute("state").Value = _state _
                                 And r.Attribute("specialty").Value = _specialty
                                 Select r

Open in new window

0
Larry Brister
Asked:
Larry Brister
  • 4
  • 3
1 Solution
 
käµfm³d 👽Commented:
So filling _specialty with "L&D" doesn't work?
0
 
Larry Bristersr. DeveloperAuthor Commented:
I get the red underline and this message on mouse over

specialty="L&D"

"Entity D is not defined
0
 
käµfm³d 👽Commented:
Huh? In VB?

In other words, if you do this:

Dim regionElements = From r In doc.Descendants("StateSpecialty") _
                                 Where r.Attribute("state").Value = _state _
                                 And r.Attribute("specialty").Value = "L&D"
                                 Select r

Open in new window


...do you still have the error?

One thing I just thought of:  Is this an ASP.NET application? If so, is this query in the markup or the code-behind?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Larry Bristersr. DeveloperAuthor Commented:
Kaufmed..
Yes..  vb.net

Code Behind
0
 
käµfm³d 👽Commented:
If the query is in code-behind, then there should not be an issue. If you are working in the markup, then there could be an issue with encoding, since the ASP.NET markup is (last I recall) XHTML-based.
0
 
Larry Bristersr. DeveloperAuthor Commented:
kaufmed...
Taking a look at that when I get back in the office tomorrow.
0
 
Larry Bristersr. DeveloperAuthor Commented:
Duh in me...had a typo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now