0

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.

Kevin
  • 2,684
  • 6
  • 35
  • 64
  • why would you use regex for this, and not simply try parsing it as xml? (xsd optional) – Marc Gravell Dec 04 '13 at 14:29
  • Note, the XElement above in the question – Kevin Dec 04 '13 at 14:56
  • but if it is in an `XELement`, it *isn't* malformed. Can you give a more complete example? Also: html != xml – Marc Gravell Dec 04 '13 at 15:31
  • YouTub embeds. `` In the eyes of XElement.Parse is not a valid XML node., yes I am aware that HTML is not XML, however, XHTML, is as close to XML as you can get with HTML structuring... – Kevin Dec 05 '13 at 16:05

2 Answers2

1

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

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • @Web if somebody asks you the correct way to hammer screws in, do you tell them "hammer harder"? Or do you tell them about screwdrivers? The fact is : your current approach doesn't work, will not work and cannot work. You need a new approach. This may involve changing some things. Welcome to programming. Html and XML are not regular languages and it is incorrect to approach them with a regular expression. Html is not XML so you shouldn't be using an XML DOM. – Marc Gravell Dec 05 '13 at 16:44
  • Please fell free to stop commenting here. If you aren't going to respond with an answer to the question all you are doing is wasting time. I really don't care how it should be done, what I care about is the solution to the issue I have posted here. – Kevin Dec 05 '13 at 18:11
  • @o7thWebDesign I understand your frustration, but I maintain that what I am saying is appropriate and relevant - even if it isn't what you wanted to hear. If you want to hack something together in regex, have fun with that. A pleasure making your acquaintance. – Marc Gravell Dec 05 '13 at 18:54
-1

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

Kevin
  • 2,684
  • 6
  • 35
  • 64