1

If an aspx file compiles, is it safe to assume that it is valid XML?

Does ASP.NET work by parsing the server controls as XML?

smartcaveman
  • 41,281
  • 29
  • 127
  • 212
  • Are you asking just for fun, or do you have a specific problem you're trying to solve? – Tony Casale Mar 10 '11 at 21:23
  • @Tony Casale, I want to load an ASPX file as a text stream and get all the server controls. I guess I could try this with regex, but I was hoping for something easier like XElement.Parse().Descendants(). Any ideas? – smartcaveman Mar 10 '11 at 23:01
  • I don't know where you'd look exactly, but I'm sure you could utilize the parser libraries in the compiler to get an AST of the ASPX file. That might be more work than you're looking to put in, though. I think the regex solution is a viable one. One other suggestion might be to pre-process your ASPX files to turn anything that isn't a server control into CDATA nodes, then you would be able to use XElement and friends with impunity. I'm on Linux these days, so I can't go poking around in .NET myself :) – Tony Casale Mar 11 '11 at 19:28
  • I looked there (http://stackoverflow.com/questions/5274272/how-does-asp-net-parse-an-aspx-file-into-executable-code), but the complexity scared me a little. I've found over and over again that if I have to think really hard about a problem I'm probably doing it the wrong way. I like your idea about turning everything invalid into CDATA, but right now I'm working on an altogether different approach to the problem. – smartcaveman Mar 11 '11 at 19:33
  • Well good luck - if you figure something out let us know how you solved it! – Tony Casale Mar 11 '11 at 19:35

3 Answers3

4

No - only the asp controls need to be valid XML. It is completely "legal" to write non-XHTML code in an ASPX file.

Tony Casale
  • 1,537
  • 8
  • 7
0

I don't think you can assume that it's valid Xml for the simple reason that it can contain markup that's not valid xml or xhtml.

One quick example: You can write <br> for the "break" tag, and this will display fine in all browsers. The valid Xhmtl version is <br />, but this is not required.

ChrisW
  • 9,151
  • 1
  • 20
  • 34
0

XML != XHTML != ASPX

You can test this by making a DIV and putting "Hello's to all of you" which would be valid ASP and XHTML but not valid XML: "Hello&#39;s to all of you"

SQLMason
  • 3,275
  • 1
  • 30
  • 40