Handle Ampersand in XML Linq

Posted on 2014-04-23
Last Modified: 2016-02-15
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
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

Question by:lrbrister
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40018489
So filling _specialty with "L&D" doesn't work?

Author Comment

ID: 40018513
I get the red underline and this message on mouse over


"Entity D is not defined
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40018566
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 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?
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.


Author Comment

ID: 40018583

Code Behind
LVL 75

Accepted Solution

käµfm³d   👽 earned 500 total points
ID: 40018595
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.

Author Comment

ID: 40018631
Taking a look at that when I get back in the office tomorrow.

Author Closing Comment

ID: 40032425
Duh in me...had a typo

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question