Search code examples
.netxmlregexxelement

RegEx To Make sure all attributes are valid


I am running into an issue in a .Net 3.5 site I inherited.

The issue is the site uses XElements everywhere to render the content on some pages. But, I am noticing that with certain YouTube video embeds, I am getting errors stating that there is an unexpected > and the XML is malformed.

I narrowed it down to the use of the allowfullscreen attribute in the newer YouTube embed codes.

So, what I'm wondering is if there is a RegEx that I could use to make sure that attributes like this have at least the structure of attribute="" to satisfy the valid XML need.


Solution

  • Since all pertinent videos in this instance will be from youtube, and include the allowfullscreen attribute, the answer was simply add: .Replace("allowfullscreen", "allowfullscreen=""true""")