HTML敏捷性包上创建保存HTML文件在C#中的字符无关 [英] Html Agility Pack creating irrelevant characters on save html file in c#
问题描述
我对项目使用asp.net MVC3 C#的工作。我想改变一些HTML元素
I am working on project using asp.net mvc3 C# . I want to change some html element
这是C#一样的宽度,高度等属性,我有一个简单的(_ Layout.cshtml)文件
attributes by c# like width , height etc. I have a simple (_Layout.cshtml) file
<html> <head>
<link href="@Url.Content("file.css")" rel="stylesheet" type="text/css" />
<body>
<a href="#" id="link1" title="@Function.ConfigElement("FacebookLink")" ></a>
</body>
</head> </html>
所以我使用的HTML敏捷包加载和保存此文件
So i am using html agility pack to load and save this file
HtmlDocument doc= new HtmlDocument();
doc.load("_Layout.cshtml");
doc.GetElementbyId("link1").Attributes.Add("title", "@Function.ConfigElement("NewLink")");
doc.save("_Layout.cshtml");
在保存文件的输出是这样的。
After saving file output is like this
<html> <head>
<link href="@Url.Content("file.css")"="" rel="stylesheet" type="text/css" />
<body>
<a href="#" id="link1" title="@Function.ConfigElement("NewLink")"="" ></a>
</body>
</head> </html>
在(链接HREF)
和(锚标题)
节省一些额外的字符
in (link href)
and (anchor title)
saving some extra characters
我如何才能避免这个问题..
是否有解析HTML在C#中asp.net mvc的任何其它解决方案。
How can i avoid this problem .. Is there any other solution for parse html in c# for asp.net mvc.
其实我想在这些HTML元素属性添加一些服务器端功能
Actually I want to add some server side function in these html element attributes
推荐答案
随着计算器的语法高亮提示巧妙,你的HTML是非常无效的。
As StackOverflow's syntax highlight subtly hints, your HTML is extremely invalid.
href="@Url.Content("file.css")"
这实际上是两个属性: HREF =@ Url.Content(
和 file.css)
。 (没有值)
This is actually two attributes: href="@Url.Content("
and file.css")"
. (which has no value)
您不能使用HTML解析器来解析剃刀标记。结果
相反,你应该用实际的剃刀解析器。
You can't use an HTML parser to parse Razor markup.
Instead, you should use the actual Razor parser.
这篇关于HTML敏捷性包上创建保存HTML文件在C#中的字符无关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!