RegEx To Make sure all attributes are valid

72 views Asked by At

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.

2

There are 2 answers

0
Kevin On BEST ANSWER

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""")

3
Marc Gravell On

You are trying to parse html, not XML. Use an HTML parser. For example the "HTML Agility Pack" would be ideal.