?
Solved

Write "&" not "&" to XML file with Linq

Posted on 2013-12-04
4
Medium Priority
?
960 Views
Last Modified: 2016-02-10
I am stuck.  I have an XML file that I am using Linq to edit.  This particular XML file has an ampersand (&) in the text of a Tag.  I am editing other parts of this string, but the '&' should not be touched.  However, when I go to write my XML to disk, the '&' is replaced with '&'  I understand that ampersands are illegal characters in XML and that is why this happens, but this particular file has to have it.  It is not my file, so I can't help that fact.

Rough example:
XElement root = XElement.Load(localXMLPath);
var myElement= root.Element("System").Element("Math");
myElement.Value =  = "Object1&Object2";
root.Save(localXMLPath);

Open in new window


Output of myElement tag is always "Object1&Object2"

Hope that explains the issue and I hope there is a workaround other than writing it to disk and then using a text editor to remove the "amp;".  Thanks.
0
Comment
Question by:efryevt
[X]
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
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:paulfarmer
ID: 39695865
0
 

Accepted Solution

by:
efryevt earned 0 total points
ID: 39695967
To elaborate for anyone that comes across this questions.  I think what paulfarmer was pointing out was all XML parsers should inherently handle the "&" entity.  If not I guess declaring it will fix it.  I think this link has a better explanation. http://www.ibm.com/developerworks/library/x-entities/

Thanks, paulfarmer.
0
 
LVL 4

Expert Comment

by:paulfarmer
ID: 39696021
That is what I was pointing out. And, I agree, I should have explained that.
0
 

Author Closing Comment

by:efryevt
ID: 39705695
Single link, no explanation.  Was pretty obscure to the actual solution.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 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