0

The problem is when a try to set an XmlAttribute value with the '>' char. It escape with the value '>', but '>' es valid because it is into an attribute value. Example:

var element = xmlDoc.CreateElement("Studient");
element.SetAttribute("Year", ">3");
xmlDoc.DocumentElement.AppendChild(element);
xmlDoc.Save(csprojPath);

In this case it produce <Studient Year="&gt;3" xmlns="" />. How can i get <Studient Year=">3" xmlns="" /> ?

Alexander Leyva Caro
  • 1,183
  • 1
  • 12
  • 21
  • Disappoint you. See [here](http://stackoverflow.com/q/5665967/5045688). – Alexander Petrov Aug 24 '15 at 22:00
  • It's not valid XML if you put the `>` character into the attribute unescaped. Why would you want to do that? The means you use to *read* the XML should unescape escaped values, no problem. Are you working with some kind of homegrown system? – ErikE Aug 24 '15 at 22:03
  • @ErikE No it is a valid xml. you can test it by yourself http://www.xmlvalidation.com/ XmlDocument or XDocument can load it without any problem. – Eser Aug 24 '15 at 22:25
  • @Eser My apologies. I guess I was thinking of the `<` character, [which IS invalid](http://www.w3.org/TR/2006/REC-xml11-20060816/#syntax). – ErikE Aug 24 '15 at 22:44

1 Answers1

0

As far as I know, There is no way to create the data like ">3" in attribute value. If you open created XML in reader it will display as ">3" only. If you are parsing XML in code , you can easily convert to intended meaning. If you can use Section value instead of Attribute Value for Student Year, you can use XmlCDataSection by CreateCDataSection (for example: https://msdn.microsoft.com/en-us/library/vstudio/system.xml.xmldocument.createcdatasection(v=vs.100).aspx)

gamepop
  • 424
  • 2
  • 13