加载aspx文件到的XmlDocument [英] load aspx file into xmldocument

查看:221
本文介绍了加载aspx文件到的XmlDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够aspx页面加载到XmlDocument的变量。我怎么做?以下是我已经尝试和期待的.xml文件,而不是.aspx页。有什么办法转换成动态aspx页面转换成XML文件并加载它?谢谢

I want to be able to load aspx page into XmlDocument variable. How do I do that? Here is what I have tried and its expecting .xml file and not .aspx page. Is there any way to convert aspx page on the fly into xml document and load it? thanks

string filePath = @"C:\WebApplication1\webform4.aspx";
XmlDocument document = new XmlDocument();
document.Load(filePath);

我收到以下错误:

I get the following error:

名称不能以%字符,十六进制值0x25开始。 1号线,2位。

推荐答案

你得到这个错误的原因:

The reason you're getting that error:

名称不能以%字符,十六进制值0x25开始。 1号线,2位。

Name cannot begin with the '%' character, hexadecimal value 0x25. Line 1, position 2.

是因为的.aspx 的网页往往不是有效的XML。 ASP.NET 的.aspx 页包含指令,例如:

is because .aspx pages are often not valid XML. ASP.NET .aspx pages contain directives such as:

<%@ Page Language="C#" [possibly other stuff] %>

&LT;%@ %&GT; 不是有效的XML这就是为什么你不能加载原始ASPX页面。

<%@ and %> is not valid XML which is why you can't load the raw ASPX page.

现在,即使你要去掉这些指令,有一个相当不错的机会,除非你已经非常非常严格,所有的页面上的标记是XHTML,那么将不会加载任何

Now, even if you were to strip out these directives, there's a fairly good chance that unless you've been really, really strict and all of the markup on the page is XHTML, then that won't load either.

您可能需要使用HTML敏捷性包可以在这里找到,试图加载页面(有或无指示):

You might want to try and load the page (with or without directives) using the HTML Agility Pack which can be found here:

HTTP://htmlagilitypack.$c$cplex.com/

这篇关于加载aspx文件到的XmlDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆