Posted By: Bas | Jun 26th @ 3:03 AM
page 1 of 1
Comments: 12 | Views: 746
Bas
Bas
It finds lightbulbs.

I'm trying to manipulate an ASPX file via Linq to XML, but when I try to load the ASPX file using XDocument.Load(), it throws up the "Name cannot begin with the '%' character" exception, obviously because of the <%@ Page %> directive.

Is there anyway to have Linq ignore that line or something? I'm noticing that ScottGu's tutorial also uses XDocument.Load() to load an aspx file, but I don't see anything in his code that might prevent the % exception.

Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...

Where is he loading a .aspx file? I don't see it.

Fact is that raw aspx files are not valid XML, (not just the lines at the top, but any <% %> block including databinding expressions etc.) so you can't do this without modifying the aspx file first.

stevo_
stevo_
Human after all

Could perhaps configure/adapt an xml reader so that it can understand / ignore code blocks? not sure how much work that would be..

vesuvius
vesuvius
The Curious Incident of the Dog in the Night-time

Its not even HTML on his side, the example is using REST and he is loading an XML file from someplace.rss.aspx RSS is always XML and not HTML or XHTML which is what ASPX is. I'd be interested fo find out what you are tying to do?

Going the _stevo route would require writing a parser (non trivial) so you'd probably use Sharp Develop or Actipro

 

I wouldn't recommend that, because the <% %> tags won't parse with XDocument.

Dr Herbie
Dr Herbie
Horses for courses

How about reading the ASPX file into memory, replacing the '<%' and '%>' with XML-valid markers ('<_percentgoesghere_' and '_percentgoeshere_>' ?), process as XML, then put back the '<%' and '%>'.

Herbie

 

aspx files can contain anything (CSS, JavaScript...), and HTML != XHTML, it would require a bit more effort than that

Dr Herbie
Dr Herbie
Horses for courses

Hmm.  Sounding more and more like a customer parser is required Sad

Herbie

how about creating a custom project template?

>I'm almost ready to just read the whole thing into a massive string, find the opening and closing tags of the form element, and insert a string of code between it. Which sounds incredibly error-prone and unwieldy.
Actually that was just what I wanted to suggest, if your controls are static/asp.net controls, simple to define, I don't see a better/easier way around. You may also look into the custom project templates (like Silverlight or C++ ones) which have wizards so you'll be able to fit/set more information. The template engine may also do some replacement work for you (like it does with $targetframeworkversion$ attribute) if you figure out how to pass your own custom attribute/value pairs to it.

page 1 of 1
Comments: 12 | Views: 746
Microsoft Communities