我将常见问题解答移动到azure存储中的xml文件中,因为它们很少更改,所以我不想每次都访问它们。
我的结构如下
<?xml version="1.0" encoding="utf-8" ?>
<Faqs>
<Faq question="Welcome to our updated FAQ!" number="0" category="welcome" >
<Answer>
<p> We have updated a lot of the content on our site, including this new FAQ page. We cannot possibly think of every question you night have so please feel free to ask us to put your questions and the answers on this page.
You can do so by clicking the link below and sending us a contact form with your question(s)
</p>
</Answer>
<ImageUrl value=""/>
</Faq>
<Faq question="What benefits does the product provide?" number="1" category="product-information" >
<Answer>
<p> A decrease in fuel consumption, substantial improvement of DPF's and an overall increase in fuel burn efficiency translate to substantial emission reductions as well. The emission benefits are achieved due to a
<ul>
<li>More Complete Combustion</li>
<li>Lower Operating Temperature</li>
<li>Lower Overall Engine Pressure</li>
</ul>
These factors account for the <strong>reduction of unburned</strong> carbon being released during the exhaust stroke of the engine and/or back into the oil as soot.
</p>
<div>
<img alt="2strokediesel" src="~/images/2strokediesel.png" />
<span class="image-caption">2-stroke diesel engine with the product catalytic coating area shown (orange shading)</span>
</div>
</Answer>
<ImageUrl value=""/>
</Faq>
...rest removed
我认为我将存储整个html而不是文本,以便于检索和创建页面,但是我的代码未将html显示为存储在xml文件中的html。
要么不可行(这种情况很少发生),要么有某种方式可以对返回的值进行编码/解码,以便其正确显示。
任何帮助表示赞赏。
这是页面一部分的剃须刀
<!-- Product Information -->
<h2 class="h3 font-w600 push-30-t push">@ti.ToTitleCase(Model.ProductInformationFaqs[0].Category)</h2>
@for (var i = 0; i < Model.ProductInformationFaqs.Count; i++)
{
var identifier = $"#faq1_q{i + 1}";
<div id="faq1" class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse"
data-parent="#faq1"
href="@identifier">@Model.ProductInformationFaqs[i].Question</a>
</h3>
</div>
@if (i == 0)
{
<div id="@identifier.Replace("#","")" class="panel-collapse collapse in">
<div class="panel-body">
@Html.Raw(Model.ProductInformationFaqs[i].Answer)
</div>
</div>
}
else
{
<div id="@identifier.Replace("#","")" class="panel-collapse collapse">
<div class="panel-body">
@Html.Raw(Model.ProductInformationFaqs[i].Answer)
</div>
</div>
}
</div>
</div>
}
<!-- END Product Information -->
为了完整起见
这是xml文件检索代码,以防万一我应该先在这里处理检索到的值。
public List<FaqDto> GetFaqItems()
{
var query = _doc.Descendants("Faq")
.Select(x => new FaqDto()
{
Category = x.Attribute("category")?.Value,
Question = x.Attribute("question")?.Value,
FaqNumber = Convert.ToInt16(x.Attribute("number")?.Value),
Answer = x.Element("Answer")?.Value,
ImageUrl = x.Element("ImageUrl")?.Attribute("value")?.Value
}).ToList();
return query;
}
For example:
xml中的常见问题#1应该显示一个看起来像这样的无序列表
<p>
A decrease in fuel consumption, substantial improvement of DPF's and an overall increase in fuel burn efficiency translate to substantial emission reductions as well. The emission benefits are achieved due to a
<ul>
<li>More Complete Combustion</li>
<li>Lower Operating Temperature</li>
<li>Lower Overall Engine Pressure</li>
</ul>
These factors accounts for the <strong>reduction of unburned</strong> carbon being released during the exhaust stroke of the engine and/or back into the oil as soot.
</p>
但是看起来像这样
答案 0 :(得分:0)
如果要从attribute的xml文件元素中检索html,则最好将html包装在CDATA元素中。您的xml应该看起来像这样,然后它将在Asp.Net Razor或MVC应用程序中使用Html.Raw(此处为您的字符串)进行检索并正确显示
示例xml文件
<Faqs>
<Faq question="Welcome to our updated FAQ!" number="0" category="welcome" >
<Answer>
<![CDATA[<html>
<p>We have updated a lot of the content on our site, including this new FAQ page. We cannot possibly think of every question you night have so please feel free to ask us to put your questions and the answers on this page. You can do so by clicking the button below and sending us a contact form with your question(s)
</p>
</html>
]]>
</Answer>
<ImageUrl value=""/>
</Faq>
</Faqs>